Package org.ametys.plugins.syndication
Class FeedCache
java.lang.Object
org.apache.avalon.framework.logger.AbstractLogEnabled
org.ametys.plugins.syndication.FeedCache
- All Implemented Interfaces:
Disposable,Initializable,Component,LogEnabled,Serviceable
public class FeedCache
extends AbstractLogEnabled
implements Component, Initializable, Serviceable, Disposable
Feed cache, supports preloading multiple feeds in multiple concurrent threads.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected Cache<String, FeedResult> The user information cache.protected AbstractCacheManagerThe cache managerprotected static final StringThe feed cache idstatic final StringThe component role. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoiddispose()Get a feed.getFeedNoCache(String feedUrl) Get a feed not from the cache.voidprotected static FeedResultRetrieve a feed's content to store it into the cache.voidpreload(Collection<String> feeds) Pre-load a collection of feeds, one by thread, to avoid getting timeouts sequentially.voidservice(ServiceManager manager) Methods inherited from class org.apache.avalon.framework.logger.AbstractLogEnabled
enableLogging, getLogger, setupLogger, setupLogger, setupLogger
-
Field Details
-
ROLE
The component role. -
CACHE_ID
The feed cache id -
_cacheManager
The cache manager -
_cache
The user information cache.
-
-
Constructor Details
-
FeedCache
public FeedCache()
-
-
Method Details
-
service
- Specified by:
servicein interfaceServiceable- Throws:
ServiceException
-
initialize
- Specified by:
initializein interfaceInitializable- Throws:
Exception
-
preload
Pre-load a collection of feeds, one by thread, to avoid getting timeouts sequentially.- Parameters:
feeds- the feeds to preload.
-
getFeedNoCache
Get a feed not from the cache.- Parameters:
feedUrl- the feed.- Returns:
- the feed result.
- Throws:
IOException- if an error occurs while loading the feed
-
getFeed
Get a feed.- Parameters:
feedUrl- the feed.lifeTime- the amount of date or time to be added to the field- Returns:
- the feed response.
-
loadFeed
protected static FeedResult loadFeed(String feedUrl, org.apache.hc.client5.http.classic.HttpClient httpClient, Logger logger) Retrieve a feed's content to store it into the cache.- Parameters:
feedUrl- the feed to load.httpClient- the client to use to load the feedlogger- the logger- Returns:
- the feed content.
-
dispose
- Specified by:
disposein interfaceDisposable
-