Home | Trees | Index | Help |
|
---|
|
Caching proxy for object retrieval and caching.
Object factories ("fetchers") are registered in the Cache
object and used
to e.g. retrieve requested objects from network. They are called only when
the requested object is not in the cache or is not fresh enough.
A state (freshness level) name may be provided when requesting an object. When the cached item state is "less fresh" then requested, then new object will be retrieved.
Following states are defined:
- 'new': always a new object should be retrieved.
- 'fresh': a fresh object (not older than freshness time)
- 'old': object not fresh, but most probably still valid.
- 'stale': object known to be expired.
Method Summary | |
---|---|
Initialize a Cache object. | |
str |
Add an item to the cache. |
CacheItem |
Get an item from the cache. |
Force cache item state change (to 'worse' state only). | |
int |
Get the number of items in the cache. |
Remove purged and overlimit items from the cache. | |
Remove a running fetcher from the list of active fetchers. | |
Request an object with given address and state not worse than state . | |
Set the fetcher class. | |
Do the regular cache maintenance. | |
str |
Update state of an item in the cache. |
Instance Variable Summary | |
---|---|
timedelta | default_expiration_period : default expiration period (in seconds). |
timedelta | default_freshness_period : default freshness period (in seconds). |
timedelta | default_purge_period : default purge period (in seconds). |
int |
max_items : maximum number of items to store. |
Method Details |
---|
__init__(self,
max_items,
default_freshness_period=datetime.timedelta(0, 3600),
default_expiration_period=datetime.timedelta(0, 43200),
default_purge_period=datetime.timedelta(1))
Initialize a |
add_item(self, item)Add an item to the cache. Item state is updated before adding it (it will not be 'new' any more).
|
get_item(self, address, state='fresh')Get an item from the cache.
|
invalidate_object(self, address, state='stale')Force cache item state change (to 'worse' state only).
|
num_items(self)Get the number of items in the cache.
|
purge_items(self)Remove purged and overlimit items from the cache. TODO: optimize somehow. Leave no more than 75% of |
remove_fetcher(self, fetcher)Remove a running fetcher from the list of active fetchers.
|
request_object(self, address, state, object_handler, error_handler=None, timeout_handler=None, backup_state=None, timeout=datetime.timedelta(0, 3600), freshness_period=None, expiration_period=None, purge_period=None)Request an object with given address and state not worse thanstate . The object will be taken from cache if available, and
created/fetched otherwise. The request is asynchronous -- this metod
doesn't return the object directly, but the object_handler is called
as soon as the object is available (this may be before request_object
returns and may happen in other thread). On error the error_handler
will be called, and on timeout -- the timeout_handler .
|
set_fetcher(self, fetcher_class)Set the fetcher class.
|
tick(self)Do the regular cache maintenance. Must be called from time to time for timeouts and cache old items purging to work. |
update_item(self, item)Update state of an item in the cache. Update item's state and remove the item from the cache if its new state is 'purged'
|
Instance Variable Details |
---|
default_expiration_perioddefault expiration period (in seconds).
|
default_freshness_perioddefault freshness period (in seconds).
|
default_purge_perioddefault purge period (in seconds). When 0 then items are never purged because of their age.
|
max_itemsmaximum number of items to store.
|
Home | Trees | Index | Help |
|
---|
Generated by Epydoc 2.1 on Mon Dec 26 17:57:40 2005 | http://epydoc.sf.net |