Persistences Caching - File Reference

The basics

If your want to cache File references of already existing files, which has been stored by other means.

This holds the key "file.getName()", with value "file".

You can add "files" from any where, but it will only restore from "caching directory", and the name of the file is the key "file.getName()".

But the constructor needs a "CachingDirectory" from where it will try to restore the file-reference cache in case of a "reboot". But only from that directory and it subdirectories if defined.

The expiration time is set on the file using - getFile().setLastModified(expireDateTime.getTime());

DefaultLRUCachingMap<String, File> map = new DefaultLRUCachingMap<String, File>(configuration,new DefaultFilenameFileReferenceValueManager(cachingDirectory,persistencesRestoreMethod));
map.put(file.getName(), file);

Default implementations

I have created
class which extended from DefaultLRUCachingMap, to simplify usages.

DefaultFilenameFileReferenceLRUCachingMap map = new DefaultFilenameFileReferenceLRUCachingMap(DefaultLRUCachingMapConfiguration.ONE_DAY(),new CachingDirectory(new File("c:/temp/xmlcache")),PersistencesRestoreMethod.DELETE_ALL);

A convenience "PUT" method has been provided in
to ease the adding of new files.
public File put(File file) throws NullPointerException;


There is also a factory class to all this -

So the code above can in reality be done like.
DefaultFileReferenceLRUCachingMap cache = LRUCachingMapFactory.createFileReferenceCache(DefaultLRUCachingMapConfiguration.ONE_DAY(), new CachingDirectory(new File("c:/temp/files")), PersistencesRestoreMethod.DELETE_ALL);

NOTE: Be aware that this implementation do not handle store or retrieve of values stored in the files, only the handle to the FILE, is "remove", "cleanup", "removeAll" and "restore" which will DELETE the file.