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());
		// ...
		// ...
	}    
}}
About this article
Last change 2019-03-14
Topics