John Lindal![]()
Cache which drops items based on a user-defined expiration criterion, e.g., age. The data store is configurable, so you can layer this on top of an MRU cache (http://yuilibrary.com/gallery/show/mru-cache) to limit both key lifetime and total memory.
Example of creating different types of expiration caches.
<script src="http://yui.yahooapis.com/3.5.1/build/yui/yui-min.js"></script>YUI({
//Last Gallery Build of this module
gallery: 'gallery-2012.05.23-19-56'
}).use('gallery-expiration-cache', function(Y)
{
// create a cache where all items expire after 1 hour (milliseconds)
var time_cache = new Y.ExpirationCache({ expire: 3600000 });
time_cache.put('foo', 'bar');
var data = time_cache.get('foo');
// create a cache where all items expire after 10 reads
var usage_cache = new Y.ExpirationCache(
{
meta: function(value)
{
return {counter:0};
},
expire: function(meta, value)
{
meta.counter++;
return (meta.counter > 10);
}
});
});
© 2006-2013 Yahoo! Inc. All rights reserved.
All code on this site is licensed under the BSD License unless stated otherwise.
About This Site · Security Contact Info