Versions Compared
compared with
Key
- This line was added.
- This line was removed.
- Formatting was changed.
Excerpt |
---|
Access or invalidate a cached value... |
Syntax
Code Block | ||||||
---|---|---|---|---|---|---|
| ||||||
var value = Cache.key; // get a cached value
Cache.key = void 0; // invalidate a cached value |
Getting a cached value
When defining a new cache, using the Cache() function, a "key" is specified. This key becomes a property on the global Cache object, allowing you to retrieve the cached value. If the cache has expired, the value is automatically updated next time you access the property.
For example, if you've defined a "foo" key, you can get it's value as follows:
Code Block | ||||||
---|---|---|---|---|---|---|
| ||||||
var foo = Cache.foo; // get a cached value for key "foo" |
Invalidating a cache
You can invalidate a cache key at any time, forcing it's value to be updated the next time it is accessed.
For example, if you want to force the "foo" key to refresh its value, do this:
Code Block | ||||||
---|---|---|---|---|---|---|
| ||||||
Cache.foo = void 0; // invalidate the cache for key "foo"
var foo = Cache.foo; // generates new value for "foo" key and caches it |