(info) This AI is still in early stages of development.

Cache.key

Access or invalidate a cached value...

 

Syntax

var value = Cache.key; // get a cached value
 
Cache.key = void Cache; // 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:

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:

Cache.foo = void Cache; // invalidate the cache for key "foo"
 
var foo = Cache.foo; // generates new value for "foo" key and caches it
You need to define keys first using Cache().
Availability STABLE

Requires:

Contents

Jump to:

Cache API

Topics: