Skip to main content

A simple database-backed cache for storing JSON-serializable values with optional expiration.

Project description

plain.cache

A simple database-backed cache for storing JSON-serializable values with optional expiration.

The Plain Cache stores JSON-serializable values in a CachedItem model. Cached data can be set to expire after a certain amount of time.

Access to the cache is provided through the Cached class.

from plain.cache import Cached


cached = Cached("my-cache-key")

if cached.exists():
    print("Cache hit and not expired!")
    print(cached.value)
else:
    print("Cache miss!")
    cached.set("a JSON-serializable value", expiration=60)

# Delete the item if you need to
cached.delete()

Expired cache items can be cleared by running chores.

CLI

  • plain cache clear-expired - Clear all expired cache items
  • plain cache clear-all - Clear all cache items
  • plain cache stats - Show cache statistics

Installation

Install the plain.cache package from PyPI:

uv add plain.cache

Add plain.cache to your INSTALLED_PACKAGES:

# app/settings.py
INSTALLED_PACKAGES = [
    # ...
    "plain.cache",
]

Run migrations to create the cache tables:

plain migrate

Project details


Download files

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

Source Distribution

plain_cache-0.22.0.tar.gz (6.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

plain_cache-0.22.0-py3-none-any.whl (10.2 kB view details)

Uploaded Python 3

File details

Details for the file plain_cache-0.22.0.tar.gz.

File metadata

  • Download URL: plain_cache-0.22.0.tar.gz
  • Upload date:
  • Size: 6.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.9.9 {"installer":{"name":"uv","version":"0.9.9"},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for plain_cache-0.22.0.tar.gz
Algorithm Hash digest
SHA256 9434788f4b3732f9cb974c297cf764af0be541ed2bd5cc969cfec10a12e67bd0
MD5 302b7fe40c496a03ee18936e8987c4f1
BLAKE2b-256 17c52e82f16ee447c4ecbcee9b74c7b36f9d1ccf899c1bfddda761be1b65b016

See more details on using hashes here.

File details

Details for the file plain_cache-0.22.0-py3-none-any.whl.

File metadata

  • Download URL: plain_cache-0.22.0-py3-none-any.whl
  • Upload date:
  • Size: 10.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.9.9 {"installer":{"name":"uv","version":"0.9.9"},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for plain_cache-0.22.0-py3-none-any.whl
Algorithm Hash digest
SHA256 edd6a15e5f1830a219b2131ebdc89843662a1c5502ebfedd35cdfb66650cbb3f
MD5 36fb7bb7dd60acbc43b6a80990b12a66
BLAKE2b-256 fdf4e5aedcde0a92d74fa0a343a875bb988506dda972704d02284c60507b699d

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page