Added tag 0.3.0 for changeset f1ded053e43a
pkg: prepare 0.3
schema: do not try to create the table if it already exists
This small library allows to cache costly things within a postgresql table.
keys
and values
are bytes.
To initialize the cache, type:
$ dbcache init-db postgresql://foo:bar@postgresql/mydb
Example usage:
from time import sleep
from datetime import timedelta
from dbcache.api import dbcache
cache = dbcache('postgresql://foo:bar@postgresql/mydb')
assert cache.get(b'a') is None
cache.set(b'a', b'aaa')
assert cache.get(b'a') == b'aaa'
cache.delete(b'a')
assert cache.get(b'a') is None
cache.set(b'b', b'bbb', lifetime=timedelta(seconds=1))
assert cache.get(b'b') == b'bbb'
sleep(1)
assert cache.get(b'b') is None
If you merely want a simple key-value store, you can use very long
lifetimes (e.g. timedelta(days=9999)
).