News Reader Portlet Pre-Fetched Feed Planning
Behavior Summary
The Jasig community would like to add "prefetching" capabilities to the News Reader Portlet. Â This new feature should allow some sub-set of pre-defined feeds to be regularly pulled and cached on the server so that no individual user should experience a fetching delay while attempting to view that feed. Â End users should not be allowed to create prefetched feeds to prevent performance problems from overusage or poorly behaving feeds. Â Feeds should only be prefetched when they are eligible for caching between users. Â If a feed is unavailable for a period of time, the code should continue to use the latest valid copy.
Proposed Changes
The existing INewsAdapter requires access to the PortletRequest while retrieving news feeds. Â A prefetching implementation would need to be able to request feeds without access to a specific PortletRequest object.
AntiSamy Configuration
AntiSamy policy files are currently configured on a portlet-by-portlet basis using the portlet preferences API. Â While this makes it easy to define both default and portlet-specific values, it places some of the configuration in the PortletPreferences object, which can only be accessed via a PortletRequest. Â This strategy also makes it difficult to configure feed-specific policies.
We should instead define a default in configuration.properties, overriding this on a feed-specific basis by using a NewsDefinition parameter.
New IPrefetchableNewsAdapter API
The current news adapter API defines a single feed retrieval method that takes a NewConfiguration and a PortletRequest object as parameters. Â Both these objects are user-specific and it would not be prudent to request a feed using these user-specific objects in the absence of an actual user request.
Â
public interface INewsAdapter { public NewsFeed getSyndFeed(NewsConfiguration config, PortletRequest request); }
To enable feed prefetching, we can create a an extension of the interface that allows prefetching. Â This interface would add an additional method that retrieves a feed simply from the NewsDefinition object. Â These feeds should be explicitly marked in the parameters as prefetched or not, and we might also want to configure parameters such as the fetch frequency.
public interface IPrefetchableNewsAdapter extends INewsAdapter {   public NewsFeed getSyndFeed(NewsDefinition def); }
Â
prefetchable NewsDefinition Parameters
- prefetching enabled/disabled
- fetch frequency
Caching and Prefetching Implementation
Feeds may be regularly prefetched using either the Spring Timer API (in the JSR-286 version) or Quartz. Â Feed prefetching might work by:
- Query database for registered feeds with prefetching enabled
- Use Quartz/Spring Timer to regularly fetch feeds. Â Upon successful fetch, update cache.
- Caching via ehcache configured such that feed should only be fetched by timer job. Â Optionally persist to disk.
Â
Â