John Lindal![]()
Cache which drops least used items to satisfy a user-defined criterion, e.g., total size or number of items. This can be used as the data store for Expiration Cache (http://yuilibrary.com/gallery/show/expiration-cache) to limit both key lifetime and total memory.
Example of creating different types of MRU 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-mru-cache', function(Y)
{
// create a cache which holds up to 500M
var size_cache = new Y.MRUCache(
{
metric: function(value)
{
return value.length;
},
limit: Math.pow(2, 29) // 500M
});
size_cache.put('foo', 'bar');
var data = size_cache.get('foo');
// create a cache which holds up to 1000 items
var count_cache = new Y.MRUCache(
{
metric: function(value)
{
return +1;
},
limit: 1000
});
});
© 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