utilities - cache
Die nachfolgenden Inhalte sind nur in englischer Sprache verfügbar.
The cache
module provides a function for caching data and invalidating the global cache.
- Note that when planta link web interfaces are enabled, the jython cache is invalidated when the global setting or text constant caches are invalidated.
Functions
Function | Parameters | Return Value | Description |
---|---|---|---|
cached(func) | func: Function to decorate | Decorator to mark a function to be cached. When called inside of a web interface, the cache read/write durations are recorded. | |
clear_cache() | Clears the global cache. |
Examples
Caching the return value of a function
from customizing import utilities
@utilities.cached
def _get_user_language(user):
query = """select
u.language
from
User u
where
u.user = {}""".format(utilities.sanitize_value(user))
try:
return utilities.db_select(query)[0][0]
except IndexError:
return 'EN'