public
Description: Sharded, memcached counter for Google App Engine
Homepage:
Clone URL: git://github.com/DocSavage/sharded_counter.git
commit  c5ec5d99c4c745ed2f0ced2bc0d938246a4065d0
tree    b45dffd5b5c920d50941f3622a62f1dd6a5f6311
parent  14d2e5b3516d7ec9009d189aff07226d05f1052d
name age message
file README Loading commit data...
file counter.py
README
Sharded, memcached counter for Google App Engine with error tolerance

Copyright 2008, William T Katz.
Released under Apache License, version 2.0

Should be used for counters that handle a lot of concurrent use.
Follows pattern described in Google I/O talk:
    http://sites.google.com/site/io/building-scalable-web-applications-with-google-app-engine

Memcache is used for caching counts and if a cached count is available, it is
the most correct. If there are datastore put issues, we store the un-put 
values into a delayed_incr memcache that will be applied as soon as the next shard put is successful. Changes will only 
be lost if we lose memcache before 
a successful datastore shard put or there's a failure/error in memcache.

Usage:
    hits = Counter('hits')
    hits.increment()
    my_hits = hits.count
    hits.get_count(nocache=True)  # Forces non-cached count of all shards
    hits.count = 6                # Set the counter to arbitrary value
    hits.increment(incr=-1)       # Decrement
    hits.increment(10)

For an example of its use (early version), you can see the Tag model in the 
Bloog open-source blog software for App Engine 
(http://github.com/DocSavage/bloog).