com.arsdigita.util.url
Class URLCache

java.lang.Object
  extended bycom.arsdigita.util.url.URLCache

public class URLCache
extends Object

Helper class for caching fetched URLs. A more advanced implementation of com.arsdigita.util.Cache which rather than being capacity limited in terms of number of stored keys, it is limited according to memory usage.


Field Summary
static int FIFTEEN_MINUTES
           
 
Constructor Summary
URLCache()
          Create a new URLCache.
URLCache(long size)
          Create a new URLCache with a maximum size of size characters.
URLCache(long size, long expiryTime)
          Create a new URLCache with a maximum size of size characters.
 
Method Summary
 long getCurrentSize()
           
 long getDefaultExpiryTime()
          Returns default expiry time for cached items.
 long getMaxSize()
          Returns max size - Maximum memory usage allowed for the data stored in the cache.
 Collection getURLS()
          Utility method to return all URLs currently in the cache.
 void purge(String url)
          removes a url from the cache
 void purgeAll()
          Purges the entire cache.
 void purgeExpired()
          Immediately removes any expired entries from the cache.
 String retrieve(String url)
          Deprecated. use retrieveData(String url)
 URLData retrieveData(String url)
          retrieves a url from the cache, returning null if not present or it has expired.
 void setDefaultExpiryTime(long defaultExpiryTime)
          Sets default expiry time for cached items.
 void setMaxSize(long maxSize)
          Sets max size - Maximum memory usage allowed for the data stored in the cache.
 void store(String url, String data)
          Deprecated. use store(String url, URLData data)
 void store(String url, String data, long expiry)
          Deprecated. use store(String url, URLData data, long expiry)
 void store(String url, URLData data)
          Stores data for a url in the cache.
 void store(String url, URLData data, long expiry)
          Stores data for a url in the cache.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

FIFTEEN_MINUTES

public static final int FIFTEEN_MINUTES
See Also:
Constant Field Values
Constructor Detail

URLCache

public URLCache()
Create a new URLCache. If more elements are put into the cache than it can hold, expired items will be evicted.


URLCache

public URLCache(long size)
Create a new URLCache with a maximum size of size characters. If more elements are put into the cache than it can hold, expired items will be evicted.

Parameters:
size - cache size in characters

URLCache

public URLCache(long size,
                long expiryTime)
Create a new URLCache with a maximum size of size characters. If more elements are put into the cache than it can hold, expired items will be evicted.

Also allows an expiration time to be set; items in the cache that are older than that time will be evicted.

Parameters:
size - cache size in characters
expiryTime - default expiry time for cached items. When retrieving an item, if its age exceeds expiry time, then it will be discarded.
Method Detail

getCurrentSize

public long getCurrentSize()
Returns:
The current size of the cache.

getMaxSize

public long getMaxSize()
Returns max size - Maximum memory usage allowed for the data stored in the cache. When exceeded, expired items are evicted until there is sufficient space for the new item. If this is not enough, items will be randomly evicted.

Returns:
max size - Maximum memory usage allowed for the data stored in the cache. When exceeded, least recently used items are evicted until there is sufficient space for the new item.

getURLS

public Collection getURLS()
Utility method to return all URLs currently in the cache.


setMaxSize

public void setMaxSize(long maxSize)
Sets max size - Maximum memory usage allowed for the data stored in the cache. When exceeded, expired items are evicted until there is sufficient space for the new item. If this is not enough, items will be randomly evicted. Warning: Shrinking the cache size will cause the cache to immediately purge excess entries to maintain the class invariant.

Parameters:
maxSize - - Maximum memory usage allowed for the data stored in the cache. When exceeded, least recently used items are evicted until there is sufficient space for the new item.

getDefaultExpiryTime

public long getDefaultExpiryTime()
Returns default expiry time for cached items. When retrieving an item, if its age exceeds expiry time, then it will be discarded.

Returns:
expiry time - default expiry time for cached items. When retrieving an item, if its age exceeds expiry time, then it will be discarded. Default expiry time is 15*60*1000.

setDefaultExpiryTime

public void setDefaultExpiryTime(long defaultExpiryTime)
Sets default expiry time for cached items. When retrieving an item, if its age exceeds expiry time, then it will be discarded.

Parameters:
defaultExpiryTime - - default expiry time for cached items. When retrieving an item, if its age exceeds expiry time, then it will be discarded. Default expiry time is FIFTEEN_MINUTES.

store

public void store(String url,
                  String data)
Deprecated. use store(String url, URLData data)


store

public void store(String url,
                  URLData data)
Stores data for a url in the cache. Expiry time is the default expiry time.

Parameters:
url - - URL to be stored in the cache.
data - - data to be stored in the cache

store

public void store(String url,
                  String data,
                  long expiry)
Deprecated. use store(String url, URLData data, long expiry)


store

public void store(String url,
                  URLData data,
                  long expiry)
Stores data for a url in the cache.

Parameters:
url - - URL to be stored in the cache.
data - - data to be stored in the cache
expiry - - expiry time in milliseconds.

purge

public void purge(String url)
removes a url from the cache


purgeAll

public void purgeAll()
Purges the entire cache.


purgeExpired

public void purgeExpired()
Immediately removes any expired entries from the cache.


retrieve

public String retrieve(String url)
Deprecated. use retrieveData(String url)

retrieves a url from the cache, returning null if not present or it has expired.


retrieveData

public URLData retrieveData(String url)
retrieves a url from the cache, returning null if not present or it has expired.



Copyright (c) 2004 Red Hat, Inc. Corporation. All Rights Reserved. Generated at July 21 2004:2337 UTC