Package elisa :: Package core :: Package utils :: Module caching

Module caching

source code

Caching and serialization facilities.

Functions
unicode
get_cache_path(cache_dir)
Return the absolute path to a specific cache directory.
source code
unicode
get_pictures_cache_path()
Returns: the absolute path to the pictures cache directory
source code
unicode
get_cached_file_path(uri, cache_path, extension=None)
Return the full path to a file cached on disk corresponding to the URI.
source code
unicode
get_cached_image_path(image_uri)
Specialized implementation of get_cached_file_path for images.
source code
unicode
cache_to_file(data, cache_file_path)
Write some data to a cache file on disk for faster subsequent access.
source code
elisa.core.utils.defer.Deferred
get_and_cache_to_file(uri, cache_path)
Get a distant resource over HTTP if needed and cache it.
source code
 
serialize(obj, dump_file_path)
Serialize an object to a file on disk.
source code
object

@raise IOError: if the file cannot be read

deserialize(dump_file_path)
De-serialize a object from a file on disk.
source code

Imports: md5, os, cPickle, default_config, defer, get_page


Function Details

get_cache_path(cache_dir)

source code 

Return the absolute path to a specific cache directory.

The cache directory is located in the local moovida directory and will be created if it doesn't exist yet.

Parameters:
  • cache_dir (unicode) - the name of the cache directory
Returns: unicode
the absolute path to the cache directory

get_pictures_cache_path()

source code 
Returns: unicode
the absolute path to the pictures cache directory

get_cached_file_path(uri, cache_path, extension=None)

source code 

Return the full path to a file cached on disk corresponding to the URI. This does not check whether the cached file actually exists.

This implementation is very loosely based on the freedesktop thumbnail specification (http://jens.triq.net/thumbnail-spec/).

Parameters:
  • uri (elisa.core.media_uri.MediaUri) - the URI to a resource to cache
  • cache_path (unicode) - the full path to the cache directory
  • extension (unicode) - the file extension the cached file should have (default None, use the URI's path extension)
Returns: unicode
the full path to the file cached on disk

get_cached_image_path(image_uri)

source code 

Specialized implementation of get_cached_file_path for images.

Parameters:
Returns: unicode
the full path to the image cached on disk

cache_to_file(data, cache_file_path)

source code 

Write some data to a cache file on disk for faster subsequent access.

If the cache file already exists, it is overwritten.

Parameters:
  • data (str) - the binary data to cache
  • cache_file_path (unicode) - the full path to the cache file
Returns: unicode
the full path to the cache file (cache_file_path)

get_and_cache_to_file(uri, cache_path)

source code 

Get a distant resource over HTTP if needed and cache it.

Parameters:
  • uri (elisa.core.media_uri.MediaUri) - the URI of the resource to retrieve and cache
  • cache_path (unicode) - the full path to the cache directory
Returns: elisa.core.utils.defer.Deferred
a deferred fired with the full path to the cached file when done

serialize(obj, dump_file_path)

source code 

Serialize an object to a file on disk.

Parameters:
  • obj (object) - the object to serialize
  • dump_file_path (unicode) - the full path to the file to dump the object to

deserialize(dump_file_path)

source code 

De-serialize a object from a file on disk.

Parameters:
  • dump_file_path (unicode) - the full path to the file the object was dumped to
Returns: object

@raise IOError: if the file cannot be read

the de-serialized object