Cached DecoratorΒΆ

SimplePlugin provides cached and mem_cached function decorators that cache return value of a function for a specified amount of time in minutes. Example:

def foo(param):
    # Do some stuff
    return bar

Here the bar value will be cached for 30 minutes.

The mem_cached decorator caches data in memory so the cache lasts as long as Kodi runs, while cached caches data to disk.

The caching decorators can be used, for example, to cache data received from a remote web-site or API, thus reducing the number of requests issued from your addon to that site or API.


Caching is based on Python object pickling so only only picklable return values can be cached. For example, generator functions (with yield statement) are not picklable so they cannot be cached.