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 AbstractCacheManager
The cache managerprotected static final String
The feed cache idstatic final String
The component role. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
dispose()
Get a feed.getFeedNoCache
(String feedUrl) Get a feed not from the cache.void
protected static FeedResult
Retrieve a feed's content to store it into the cache.void
preload
(Collection<String> feeds) Pre-load a collection of feeds, one by thread, to avoid getting timeouts sequentially.void
service
(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:
service
in interfaceServiceable
- Throws:
ServiceException
-
initialize
- Specified by:
initialize
in 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:
dispose
in interfaceDisposable
-