core (memory/cache): file caching handling, first draft:

instead of having file caching handled individually by plugins, a generic module has been added in memory.

    - Cache can be global or associated to a profile. In the later case, client.cache can be used.
    - Cache are managed with unique ids (which can be any unique unicode, hash uuid, or something else).
    - To know if a file is in cache, getFilePath is used: if the file is in cache, its absolute path is returned, else None is returned.
    - To cache a file, cacheData is used with at list the source of cache (most of time plugin import name), and unique id. The method return file opened in binary writing mode (so cacheData can - and should - be used with "with" statement).
    - 2 files will be created: a metadata file (named after the unique id), and the actual file.
    - each file has a end of life time, after it, the cache is invalidated and the file must be requested again.
This commit is contained in:
Goffi 2017-01-05 20:23:38 +01:00
commit 6872df4fd3

View file

@ -132,6 +132,9 @@ class Const(object):
NS_DELAY = 'urn:xmpp:delay'
NS_XHTML = 'http://www.w3.org/1999/xhtml'
## Directories ##
CACHE_DIR = u'cache'
## Configuration ##
if BaseDirectory: # skipped when xdg module is not available (should not happen in backend)
@ -281,6 +284,7 @@ class Const(object):
ENV_PREFIX = 'SAT_' # Prefix used for environment variables
IGNORE = 'ignore'
NO_LIMIT = -1 # used in bridge when a integer value is expected
DEFAULT_MAX_AGE = 1209600 # default max age of cached files, in seconds
## ANSI escape sequences ##