net.sourceforge.rssowl.util.archive
Class FeedCacheManager

java.lang.Object
  extended bynet.sourceforge.rssowl.util.archive.FeedCacheManager

public class FeedCacheManager
extends Object

Cache manager for RSSOwl. Any loaded newsfeed is stored in the cache folder and indexed in the newsFeedCache Hashtable. That index is serialized into a file and loaded on startup of RSSOwl. Two Hashtables manage the caching. The live cache contains Channel objects withe the URL as key, whereas the local cache contains File objects which point to the cached file where the newsfeed is stored.

Version:
1.1.3
Author:
Benjamin Pasero

Field Summary
private static String CACHE_INDEX
          File to serialize the cache index into
private static long FILE_TIME_TO_LIVE
          Max time to live for unmodified cache files (2 days)
private  Hashtable newsFeedLiveCache
          Live cache will store RSSChannels
private  Hashtable newsFeedLocalCache
          Local cache will store File reference to cached files
 
Constructor Summary
FeedCacheManager()
          Instantiate a new FeedCacheManager
 
Method Summary
 void cacheNewsfeed(String url, Channel rssChannel)
          Cache a newsfeed
private  void cleanUpCache()
          Remove those files from the archive which were not modified over a long period
private  void deleteCache()
          Delete the cache as it is no longer used in RSSOwl
private  void deserializeCache()
          Load the local cache index from local file
 Channel getCachedNewsfeed(String url)
          Get a cached newsfeed from the feed cache
 boolean isNewsfeedCached(String url)
          Check if a newsfeed is cached by a unique identifier in either the live cache (memory) or local (file)
 boolean isNewsfeedCached(String url, boolean allowLocalCache)
          Check if a newsfeed is cached by a unique identifier in either the live cache (memory) and local (file) is allowLocalCache is set to TRUE
private  File saveDocument(org.jdom.Document document)
          Save the newsfeed's XML document into a unique file in the cache dir and return the reference to the new file
private  void serializeCache()
          Save the chache index into local file
 void shutdown()
          Serialize the index on application exit and cleanup old chache items
 void unCacheNewsfeed(String url, boolean deleteLocalCache)
          Remove a newsfeed from the cache and delete its cache file
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CACHE_INDEX

private static final String CACHE_INDEX
File to serialize the cache index into

See Also:
Constant Field Values

FILE_TIME_TO_LIVE

private static final long FILE_TIME_TO_LIVE
Max time to live for unmodified cache files (2 days)

See Also:
Constant Field Values

newsFeedLiveCache

private Hashtable newsFeedLiveCache
Live cache will store RSSChannels


newsFeedLocalCache

private Hashtable newsFeedLocalCache
Local cache will store File reference to cached files

Constructor Detail

FeedCacheManager

public FeedCacheManager()
Instantiate a new FeedCacheManager

Method Detail

cacheNewsfeed

public void cacheNewsfeed(String url,
                          Channel rssChannel)
Cache a newsfeed

Parameters:
url - Unique identifier
rssChannel - The newsfeed to cache

getCachedNewsfeed

public Channel getCachedNewsfeed(String url)
Get a cached newsfeed from the feed cache

Parameters:
url - Unique identifier
Returns:
Channel The cached newsfeed

isNewsfeedCached

public boolean isNewsfeedCached(String url)
Check if a newsfeed is cached by a unique identifier in either the live cache (memory) or local (file)

Parameters:
url - Unique identifier
Returns:
boolean TRUE if newsfeed is cached

isNewsfeedCached

public boolean isNewsfeedCached(String url,
                                boolean allowLocalCache)
Check if a newsfeed is cached by a unique identifier in either the live cache (memory) and local (file) is allowLocalCache is set to TRUE

Parameters:
url - Unique identifier
allowLocalCache - If TRUE also look in local file cache
Returns:
boolean TRUE if newsfeed is cached

shutdown

public void shutdown()
Serialize the index on application exit and cleanup old chache items


unCacheNewsfeed

public void unCacheNewsfeed(String url,
                            boolean deleteLocalCache)
Remove a newsfeed from the cache and delete its cache file

Parameters:
url - Unique identifier
deleteLocalCache - If TRUE, also uncache local file

cleanUpCache

private void cleanUpCache()
Remove those files from the archive which were not modified over a long period


deleteCache

private void deleteCache()
Delete the cache as it is no longer used in RSSOwl


deserializeCache

private void deserializeCache()
Load the local cache index from local file


saveDocument

private File saveDocument(org.jdom.Document document)
                   throws IOException
Save the newsfeed's XML document into a unique file in the cache dir and return the reference to the new file

Parameters:
document - The newsfeed's document to save
Returns:
File The new cache file that was created
Throws:
IOException - If an error occurs

serializeCache

private void serializeCache()
Save the chache index into local file



RSSOwl - RSS / RDF / Atom Newsreader

SourceForge.net Logo