|
|||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||
java.lang.Objectnet.sourceforge.java.feednread.backend.cache.NewsFeedCache
Simple cache for SyndFeedInfo wrapper objects. The class
combines a live cache in memory and a persistent cache on a persistent
medium, e.g. a cache directory on a harddisk. The live cache size is limited
by
ConfigurationManager.MAX_LIVE_CACHE_SIZE_KEY
where this value denotes a maximum number of SyndFeedInfo
objects to hold in memory at the same time. The persistent cache size is
limited by
ConfigurationManager.MAX_PERSISTENT_CACHE_SIZE_KEY.
This value is specified in kilobytes.
If a SyndFeedInfo object is requested from the cache the
lookup mechanism first tries to query the live cache in memory. Only if the
requested object was not found in that first level cache the persistent cache
is queried. If then the requested object was found it is automatically put
into the live cache.
A SyndFeedInfo object can be requested from the cache by
invoking the getFeedInfo(URL) method whereas a
SyndFeedInfo object can be put into the cache by invoking the
setFeedInfo(URL, SyndFeedInfo) method.
The live cache cleanup routine cleanupLiveCache() is invoked
automatically if the configured size limit has been reached. In contrast the
persistent cache cleanup routine cleanupPersistentCache() has to be
called programatically to adjust the persistent cache to the configured size
limit. Both cleanup routines remove the oldest items first, i.e. the
SyndFeedInfo with the oldest modification date returned by
SyndFeedInfo.getLastModified(). By
default the application calls this method when it shuts down.
| Nested Class Summary | |
private class |
NewsFeedCache.CachedFilenameFilter
|
| Field Summary | |
private Map |
cachedNewsFeeds
|
private static NewsFeedCache |
SINGLE_INSTANCE
|
| Constructor Summary | |
private |
NewsFeedCache()
Creates a new NewsFeedCache.
|
| Method Summary | |
private void |
cache(URL feedUrl,
SyndFeedInfo syndFeedInfo)
Puts the specified SyndFeedInfo object into the live
cache in memory.
|
private void |
cachePersistent(SyndFeedInfo syndFeedInfo)
Caches the specified SyndFeedInfo object to a persistent
medium.
|
private void |
cleanupLiveCache()
Cleans up this the live cache. |
void |
cleanupPersistentCache()
Cleans up the persistent cache. |
void |
clearPersistentCache()
Clears this NewsFeedCache's persistent cache completely,
i.e. removes all cached NewsFeeds.
|
private double |
deletePersistent(String id)
Delete the SyndFeedInfo denoted by the
specified id from the underlying persistent cache.
|
SyndFeedInfo |
getFeedInfo(URL feedUrl)
Gets a SyndFeedInfo object from the cache. |
private SyndFeedInfo |
getFromPersistentCache(String id)
Gets the SyndFeedInfo object identified by the specified
unique id from the persistent cache.
|
private String |
getId(File f)
Gets the id of the specified persistent SyndFeedInfo.
|
static NewsFeedCache |
getInstance()
Gets the singleton instance of this NewsFeedCache.
|
void |
setFeedInfo(URL feedUrl,
SyndFeedInfo syndFeedInfo)
Puts the specified SyndFeedInfo object in the cache.
|
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
private Map cachedNewsFeeds
private static NewsFeedCache SINGLE_INSTANCE
| Constructor Detail |
private NewsFeedCache()
Creates a new NewsFeedCache.
| Method Detail |
public static NewsFeedCache getInstance()
Gets the singleton instance of this NewsFeedCache.
NewsFeedCachepublic SyndFeedInfo getFeedInfo(URL feedUrl)
Gets a SyndFeedInfo object from the cache. The lookup
mechanism first tries to query the live cache in memory. Only if the
requested object was not found in that first level cache the persistent
cache is queried. If then the requested object was found it is
automatically put into the live cache.
getFeedInfo in interface FeedFetcherCachefeedUrl - The url of the feed
SyndFeedInfo object or null if it
is not in the cache
public void setFeedInfo(URL feedUrl,
SyndFeedInfo syndFeedInfo)
Puts the specified SyndFeedInfo object in the cache.
The SyndFeedInfo object is put in the live cache
and written out to the persistent cache.
If the persistance operation failed the SyndFeedInfo
is put in the live cache nevertheless.
setFeedInfo in interface FeedFetcherCachefeedUrl - the url of the feedsyndFeedInfo - a SyndFeedInfo object for the feedpublic void cleanupPersistentCache()
Cleans up the persistent cache.
public void clearPersistentCache()
Clears this NewsFeedCache's persistent cache completely,
i.e. removes all cached NewsFeeds.
private void cache(URL feedUrl,
SyndFeedInfo syndFeedInfo)
Puts the specified SyndFeedInfo object into the live
cache in memory.
This methods cleans up the live cache if the size limit configured
through ConfigurationManager.MAX_LIVE_CACHE_SIZE_KEY
feedUrl - the url of the feedsyndFeedInfo - the SyndFeedInfo object to put into
the live cache in memoryprivate void cachePersistent(SyndFeedInfo syndFeedInfo)
Caches the specified SyndFeedInfo object to a persistent
medium.
syndFeedInfo - the SyndFeedInfo object to cache
persistent
private SyndFeedInfo getFromPersistentCache(String id)
throws IOException,
ClassNotFoundException
Gets the SyndFeedInfo object identified by the specified
unique id from the persistent cache.
id - the unique id of the SyndFeedInfo object
SyndFeedInfo from the persistent cache
IOException - if an io error occured during the cache operation
ClassNotFoundException - if a Class mismatch was
detectedprivate void cleanupLiveCache()
Cleans up this the live cache.
private double deletePersistent(String id)
Delete the SyndFeedInfo denoted by the
specified id from the underlying persistent cache.
id - the id of the persistent SyndFeedInfo
entry to delete
private String getId(File f)
Gets the id of the specified persistent SyndFeedInfo.
f - the persistent SyndFeedInfo File
null if no valid persistent
SyndFeedInfo File
|
|||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||