Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Excerpt

Access or invalidate a cached value...

 

Syntax

Code Block
themeRDark
languagejavascript
linenumberstrue
var value = Cache.key; // get a cached value
 
Cache.key = void; // 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
themeRDark
languagejavascript
linenumberstrue
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
themeRDark
languagejavascript
linenumberstrue
Cache.foo = void; // invalidate the cache for key "foo"
 
var foo = Cache.foo; // generates new value for "foo" key and caches it
Div
classdiv box notice ping

You need to define keys first using Cache().

Div
classbox

Availability

Requires:

Div
classbox

Cache API

Topics:

Child pages (Children Display)
alltrue
depthall
pageCache API
excerpttrue