Skip to main content

A postgresql backed cache system

Project description


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'

  assert cache.get(b'a') is None

  cache.set(b'b', b'bbb', lifetime=timedelta(seconds=1))
  assert cache.get(b'b') == b'bbb'
  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)).

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Built Distribution

dbcache-0.2.0-py3-none-any.whl (4.0 kB view hashes)

Uploaded py3

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Huawei Huawei PSF Sponsor Microsoft Microsoft PSF Sponsor NVIDIA NVIDIA PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page