com.dtolabs.rundeck.core.utils.cache
Class FileCache<T extends FileCache.Cacheable>

java.lang.Object
  extended by com.dtolabs.rundeck.core.utils.cache.FileCache<T>

public class FileCache<T extends FileCache.Cacheable>
extends java.lang.Object

FileCache stores items associated with a file and expires them if the file is removed or modified. The FileCache.ItemCreator interface is used to create cacheable items


Nested Class Summary
static interface FileCache.Cacheable
          Cacheable item for FileCache.
static interface FileCache.Expiration<T>
          Determines whether a cached item has expired
static interface FileCache.Expireable
          Allows expire method to be called for a cached item when it is expired from the cache
static interface FileCache.ItemCreator<T>
          Creates an item to store in the cache
static class FileCache.LastModifiedExpiration<T>
          Expires items if the lastModified of the file is greater than the cached time for the item.
 
Constructor Summary
FileCache()
          Use the FileCache.LastModifiedExpiration expiration policy by default.
FileCache(FileCache.Expiration<T> expiration)
          Use a specific expiration policy
 
Method Summary
 T get(java.io.File file, FileCache.ItemCreator<T> creator)
          Get entry for a file, and use the creator if necessary to create it.
 void remove(java.io.File file)
          Remove entry for a file.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FileCache

public FileCache()
Use the FileCache.LastModifiedExpiration expiration policy by default.


FileCache

public FileCache(FileCache.Expiration<T> expiration)
Use a specific expiration policy

Method Detail

remove

public void remove(java.io.File file)
Remove entry for a file.


get

public T get(java.io.File file,
             FileCache.ItemCreator<T> creator)
Get entry for a file, and use the creator if necessary to create it. The creator will be called if the cache is out of date for the file. If the created item is equals to any existing cached item for the file then the old item will not be replaced. Otherwise, if the old item is FileCache.Expireable then the FileCache.Expireable.expire() method will be called on it.

Parameters:
file - the ifle
creator - the item creator
Returns:
the item associated with the file, or null if none is found