Created
March 22, 2011 18:54
-
-
Save williamsjj/881801 to your computer and use it in GitHub Desktop.
Proposed interface model for paisley caching API
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class CachingInterface (object): | |
def __init__(self): | |
"To be overridden by the sub-class." | |
raise Exception("not implemented") | |
def store(key, value, rev, db=None): | |
""" | |
Store a key/value pair in the cache. Returns a Deferred. | |
Arguments: | |
key (string) - Key to store value under. | |
value (string/int/float/bool) - Value to be stored. | |
rev (string) - Revision ID of the key. | |
db (string) (optional) - Namespace under which to store the key. | |
Each caching implementation may implement | |
this differently to suit the underlying | |
caching store. If not supplied, it is | |
up to the underlying implementation to | |
determine the "default" namespace to | |
store the key in. | |
Returns: | |
Immediate Return: Twisted Deferred | |
Eventual Return: | |
* Success: True | |
* Failure: Raises an exception. | |
""" | |
raise Exception("not implemented") | |
def get(key, db=None): | |
""" | |
Retrieve a key/value pair from the cache. | |
Arguments: | |
key (string) - Key to retrieve value for. | |
db (string) (optional) - Namespace key is stored under. | |
If not supplied, uses default namespace | |
as selected by the implementation. | |
Returns: | |
Immediate Return: Twisted Deferred | |
Eventual Return: | |
* Success: (list) | |
- index 0: (bool/int/string/float) Key's value | |
- index 1: Key's revision ID. | |
* Failure: Raises an exception. | |
""" | |
raise Exception("not implemented") | |
def delete(key, db=None): | |
""" | |
Remove a key/value pair from the cache. | |
Arguments: | |
key (string) - Key to retrieve value for. | |
Returns: | |
Immediate Return: Twisted Deferred | |
Eventual Return: | |
* Success: True | |
* Failure: Raises an exception | |
""" | |
raise Exception("not implemented") |
The main reason for the db argument in the get/store methods is so that the CouchDB library can specify namespacing for caching views separately from documents since the cache object will already be instantiated when its passed in.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I like this interface. However, I think it is better to give the db=None option to the constructor of the cache plugin.