My favorites | Sign in
Project Logo
                
Search
for
Updated Sep 25, 2009 by bowman.joseph
Labels: Featured
Cache  

Cache

Cache is an object based storage mechanism which can be used to increase the performance of your appengine site by storing the values generated by performance heavy operations so that they only need to be run once.

Using Cache

Make it available simply by importing the class, and initializing it.

    from appengine_utilities.cache import Cache
    self.cache = Cache()

Once initialized, you can use cache like any other dictionary object.

    self.cache['meals'] = ['breakfast', 'lunch', 'dinner']
    self.cache['username'] = 'Bob'

All standard dictionary methods are implemented.

How Cache objects are stored

Cache data is stored both in the datastore and memcache. Every write/delete of cache data will update the memcache. During a read, first the memcache is checked, and if that fails, the datastore is checked. If a hit fails in memcache, but works in the datastore, the memcache is updated.

Cache Arguments

Cache take the following arguments on initializaion:

  • Args:
    • clean_check_percent: how often cache initialization should run the cache cleanup
    • max_hits_to_clean: maximum number of stale hits to clean
    • default_timeout: default length a cache item is good for


Comment by hervandevliert, Sep 25, 2009

In the example is a small typo 'from appengine_utilities.sessions import Cache' must be changed to 'from appengine_utilities.cache import Cache'.

Comment by bowman.joseph, Sep 25, 2009

thanks, got it


Sign in to add a comment
Hosted by Google Code