Versions Compared

Key

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

...

The key the should be read out from cache

Parameter force:boolean (optional)

Set this to true, if caching is disabled but you still wish to retrieve a value

...

Code Block
languagejs
linenumberstrue
function renderContent(contentName, cacheable, expiry)
{
  [...]

  var content = contents.findByName(mappedContentName);
  [...]

  var res = content.content;
  
  if (cacheable === "true" && (system.isDeveloperCacheActive || system.isCacheActive)) {
    cache.set("portal.renderContent#" + mappedContentName, res, true, parseInt(expiry));
  }  
  
  return res;
}

Parameter key:string (required)

The key that should be set into cache

Parameter value:string (required)

The value the key should have in cache

Parameter force:bool (optional)

Set this to true, if caching is disabled but you still wish to write into cache

Parameter expiryTimeInSeconds:int (optional)

The time in seconds of how long the key is kept in cache

cache.getOrSet(key, fun, [force], [expiryTimeInSeconds])

Retrieves a key from the cache if available and returns it. If the key is not found, the supplied function is executed and the result is saved to the key and then returned.

This saves you the hassle of manually checking for a key and setting it with some value if it hasn't been found and then using that value further.

Example

Code Block
languagejs
linenumberstrue
cache.getOrSet('myCacheKey', function() {
	// an expensive or long running function
	// ...
}, true, 86400);

Parameter key:string (required)

The key that should be set into cache

Parameter fun:function (required)

The key that should be set into cache

Parameter force:bool (optional)

Set this to true, if caching is disabled but you still wish to write into cache

Parameter expiryTimeInSeconds:int (optional)

The time in seconds of how long the key is kept in cache