core.cache

Module Contents

Functions

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

Decorator to mark a function cacheable.

flushCache(prefix: str = None, key: Union[(db.KeyClass, None)] = None, kind: Union[(str, None)] = None)

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: Union[List[str], None] = None, maxCacheTime: Union[int, None] = None)

Decorator to mark a function cacheable. Only functions decorated with enableCache are considered cacheable; ViUR will never ever cache the result of a user-defined function otherwise. 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.

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: Union[db.KeyClass, None] = None, kind: Union[str, None] = None)

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

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.