org.springframework.extensions.surf.cache
Class PersistentCache

java.lang.Object
  extended by org.springframework.extensions.surf.cache.BasicCache
      extended by org.springframework.extensions.surf.cache.PersistentCache
All Implemented Interfaces:
ContentCache

public class PersistentCache
extends BasicCache

This is a more advanced version of a cache that passivates objects to disk. If objects are cleaned out of the WeakHashMap, they are still retained on disk and can be reloaded from disk. Thus, the disk provides the true "persistent" cache and the in-memory cache still exists for performance purposes.

Author:
muzquiano

Field Summary
 
Fields inherited from class org.springframework.extensions.surf.cache.BasicCache
cache, timeout
 
Constructor Summary
PersistentCache(long default_timeout, String cacheDir)
          Instantiates a new persistent cache.
 
Method Summary
protected  boolean existsOnDisk(String pathID)
          Returns whether the disk-cached object for the given pathID exists.
 Object get(String key)
          Gets content stored in the cache
protected  File getCacheFile(String pathID)
          Returns the literal java.io.File path for the given path ID.
protected  CacheItem loadFromDisk(String pathID)
          Loads a content item from disk if it exists.
 void put(String key, Object obj, long timeout)
          Places content into the cache
 void remove(String key)
          Removes a content object from the cache.
protected  void removeFromDisk(String pathID)
          Removes a content item cached file from disk for the given path id.
protected  boolean writeToDisk(String pathID, CacheItem item)
          Serializes the given content item to disk for the given path string.
 
Methods inherited from class org.springframework.extensions.surf.cache.BasicCache
invalidate, keys, put, values
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PersistentCache

public PersistentCache(long default_timeout,
                       String cacheDir)
Instantiates a new persistent cache.

Parameters:
default_timeout - the default_timeout
cacheDir - the cache dir
Method Detail

get

public Object get(String key)
Description copied from interface: ContentCache
Gets content stored in the cache

Specified by:
get in interface ContentCache
Overrides:
get in class BasicCache
Parameters:
key - the key
Returns:
the object

remove

public void remove(String key)
Description copied from interface: ContentCache
Removes a content object from the cache.

Specified by:
remove in interface ContentCache
Overrides:
remove in class BasicCache
Parameters:
key - the key

put

public void put(String key,
                Object obj,
                long timeout)
Description copied from interface: ContentCache
Places content into the cache

Specified by:
put in interface ContentCache
Overrides:
put in class BasicCache
Parameters:
key - the key
obj - the obj
timeout - the timeout in milliseconds

existsOnDisk

protected boolean existsOnDisk(String pathID)
Returns whether the disk-cached object for the given pathID exists.

Parameters:
pathID - the path id
Returns:
true, if exists on disk

loadFromDisk

protected CacheItem loadFromDisk(String pathID)
Loads a content item from disk if it exists. Returns null if the item doesn't exist on disk. If the file on disk is corrupt, the file is cleaned up.

Parameters:
pathID - the path id
Returns:
the cache item

writeToDisk

protected boolean writeToDisk(String pathID,
                              CacheItem item)
Serializes the given content item to disk for the given path string.

Parameters:
pathID - the path id
item - the item
Returns:
true, if write to disk

removeFromDisk

protected void removeFromDisk(String pathID)
Removes a content item cached file from disk for the given path id.

Parameters:
pathID - the path id

getCacheFile

protected File getCacheFile(String pathID)
Returns the literal java.io.File path for the given path ID.

Parameters:
pathID - the path id
Returns:
the cache file


Copyright © 2009 SpringSource, Inc. All Rights Reserved.