core.cache

Module Contents

Functions

enableCache(urls[, userSensitive, languageSensitive, ...])

Decorator to wrap this cache around a function. In order for this to function correctly, you must provide

flushCache([prefix, key, kind])

Flushes the cache. Its possible the flush only a part of the cache by specifying

core.cache.enableCache(urls: List[str], userSensitive: int = 0, languageSensitive: bool = False, evaluatedArgs: List[str] | None = None, maxCacheTime: int | None = None)

Decorator to wrap this cache around a function. In order for this to function correctly, you must provide additional information so ViUR can determine in which situations it’s possible to re-use an already cached result and when to call the wrapped function instead.

..Warning: It’s not possible to cache the result of a function relying on reading/modifying

the environment (ie. setting custom http-headers). The only exception is the content-type header which will be stored along with the cached response.

Parameters:
  • urls – A list of urls for this function, for which the cache should be enabled. A function can have several urls (eg. /page/view or /pdf/page/view), and it might should not be cached under all urls (eg. /admin/page/view).

  • userSensitive – Signals wherever the output of f depends on the current user. 0 means independent of wherever the user is a guest or known, all will get the same content. 1 means cache only for guests, no cache will be performed if the user is logged-in. 2 means cache in two groups, one for guests and one for all users 3 will cache the result of that function for each individual users separately.

  • languageSensitive – If true, signals that the output of f might got translated. If true, the result of that function is cached separately for each language.

  • evaluatedArgs – List of keyword-arguments having influence to the output generated by that function. This list must be complete! Parameters not named here are ignored! Warning: Double-check this list! F.e. if that function generates a list of entries and you miss the parameter “order” here, it would be impossible to sort the list. It would always have the ordering it had when the cache-entry was created.

  • maxCacheTime – Specifies the maximum time an entry stays in the cache in seconds. Note: Its not erased from the db after that time, but it won’t be served anymore. If None, the cache stays valid forever (until manually erased by calling flushCache.

core.cache.flushCache(prefix: str = None, key: viur.core.db.Key | None = None, kind: str | None = None)

Flushes the cache. Its possible the flush only a part of the cache by specifying the path-prefix. The path is equal to the url that caused it to be cached (eg /page/view) and must be one listed in the ‘url’ param of viur.core.cache.enableCache().

Parameters:
  • prefix – Path or prefix that should be flushed.

  • key – Flush all cache entries which may contain this key. Also flushes entries which executed a query over that kind.

  • kind – Flush all cache entries which executed a query over that kind.

Examples:
  • “/” would flush the main page (and only that),

  • “/” everything from the cache, “/page/” everything from the page-module (default render),

  • and “/page/view/*” only that specific subset of the page-module.