You have been redirected from an outdated version of the article. Below is the content available on this topic. To view the old article click here.

has_cache_value()

Usage

has_cache_value(key)

Description

Checks if a cached value exists for the given key. Returns false if there is no stored value or if the stored value is expired.
This function is especially useful if the result of a JavaScript function should be cached (see Example 2).

Example 1

${has_cache_value('externalResult')}

Example 2

${{    
	let myComplexFunction = function() {
		return new Date().toString();
	};

	let cacheKey = 'myKey';

	if (Structr.hasCacheValue(cacheKey)) {

		// retrieve cached value
		let cacheValue = Structr.getCacheValue(cacheKey);
		// ...
		// ...

	} else {

		// cache the result of a complex function
		let cacheResult = Structr.cache(cacheKey, 30, myComplexFunction());
		// ...
		// ...
	}    
}}

Search results for "has_cache_value()"

has_cache_value()

Checks if a cached value exists for the given key. Returns false if there is no stored value for the given key or if the stored value is expired.

This function is especially useful if the result of a JavaScript function should be cached (see Example 2).

has_cache_value(key)