Cache Utility: Basic Caching
The Cache Utility provides a basic caching mechanism for storing key/value pairs in local JavaScript memory.
YUI().use("cache", function(Y) { // Configure Cache maximum size in the constructor var cache = new Y.Cache({max:5}); // Add entries to the Cache cache.add("key1", "value1"); cache.add("key2", "value2"); // Retrieve a cached entry var cachedentry = cache.retrieve("key1"); // Cached entry is an object with a request property and a response property alert("cached key: " + cachedentry.request + "/cached value: " + cachedentry.response); // Flush the cache cache.flush(); });
YUI().use("cache", function(Y) { // Configure Cache maximum size in the constructor var cache = new Y.Cache({max:5}); // Add entries to the Cache cache.add("key1", "value1"); cache.add("key2", "value2"); // Retrieve a cached entry var cachedentry = cache.retrieve("key1"); // Cached entry is an object with a request property and a response property alert("cached key: " + cachedentry.request + "/cached value: " + cachedentry.response); // Flush the cache cache.flush(); });