ExpirationCache Class
Cache which drops items based on a user-defined expiration criterion, e.g., age. By default, expired items are only removed when they are requested. If you want to "stop the world" and clean out the cache, call clean().
Constructor
ExpirationCache
-
config
Parameters:
-
config
Object-
[store]
Object optionalData store which implements get,put,remove,clear,keys. If not specified, a new instance of
Y.InstanceManager
is created. -
[meta]
Function optionalAttaches meta data to an item when it is added to the cache. It receives the value as an argument. If not specified, the default is to timestamp the item.
-
expire
FunctionReturns true if the item has expired. It receives the meta data and the value as arguments. If a number is specified, it is assumed to be a duration in milliseconds.
-
[stats]
Boolean optionalPass true if you want to collect basic statistics. Pass a function if you want to control what information is stored for each key. The function receives the key, the value, and the stat object.
-
Methods
clean
()
Remove all expired values.
clear
()
Remove all values.
dumpStats
()
Object
This resets all the values.
Returns:
get
-
key
Retrieve a value.
Parameters:
-
key
Stringthe key of the object to retrieve
Returns:
put
-
key
-
value
Store a value.
Parameters:
-
key
Stringthe key of the value
-
value
Objectthe value to store
Returns:
remove
-
key
Remove an value.
Parameters:
-
key
Stringthe key of the value
Returns:
replace
-
key
-
value
Store a value.
Parameters:
-
key
Stringthe key of the value
-
value
Objectthe value to store