Package org.microproxy.cache
Class DiskCacheStore
java.lang.Object
org.microproxy.cache.DiskCacheStore
- All Implemented Interfaces:
CacheStore
Keeps responses as files in a directory, so the cache survives restarts (and can serve while
offline). Each variant is one file named after a hash of its URL and
Vary values,
written to a temporary file and moved into place. The index of what is stored lives in memory,
rebuilt from the files' headers at startup; the least recently used files go first when the
size limit is reached. One store should own its directory.-
Constructor Summary
ConstructorsConstructorDescriptionDiskCacheStore(Path dir, long maxSize) Opens (creating if needed) a store indir, indexing the entries already there. -
Method Summary
Modifier and TypeMethodDescriptionintcount()Returns the number of stored responses (variants).The stored variants forkey(a URL), most recently stored first; empty if none.voidput(CachedResponse response) Storesresponse, replacing the variant of its key with the samevaryvalues.voidRemoves every variant stored forkey.longsize()Returns the totalCachedResponse.weight()of what is stored.
-
Constructor Details
-
DiskCacheStore
Opens (creating if needed) a store indir, indexing the entries already there.- Parameters:
dir- the directory backing the response cachemaxSize- the mostCachedResponse.weight()to hold, in bytes- Throws:
IOException- if the cache directory cannot be created or read
-
-
Method Details
-
get
Description copied from interface:CacheStoreThe stored variants forkey(a URL), most recently stored first; empty if none.- Specified by:
getin interfaceCacheStore- Parameters:
key- the URL whose variants to retrieve- Returns:
- the stored variants for
key(a URL), most recently stored first; empty if none
-
put
Description copied from interface:CacheStoreStoresresponse, replacing the variant of its key with the samevaryvalues.- Specified by:
putin interfaceCacheStore- Parameters:
response- the response being handled
-
remove
Description copied from interface:CacheStoreRemoves every variant stored forkey.- Specified by:
removein interfaceCacheStore- Parameters:
key- the URL whose variants to remove
-
size
public long size()Description copied from interface:CacheStoreReturns the totalCachedResponse.weight()of what is stored.- Specified by:
sizein interfaceCacheStore- Returns:
- the total
CachedResponse.weight()of what is stored
-
count
public int count()Description copied from interface:CacheStoreReturns the number of stored responses (variants).- Specified by:
countin interfaceCacheStore- Returns:
- the number of stored responses (variants)
-