Skip to main content

Cache library that allows invalidation and other shenanigans

Project description

Cacheia

Cacheia has all the core functionality for the "cacheia" package. It exposes a simple interface for multiple cache providers with added features like cache invalidation and cache expiration.

Installation

Install core with "schemas" optional to download schemas dependency:

pip install -e ./core[schemas]

Code

Cacheia mainly exposes one interface to interact with all backends and some custom exceptions:

  • Cacheia: The main interface to interact with all backends.
  • InvalidSettings: Exception raised when an invalid settings class type is passed to Cacheia.setup method.
  • KeyAlreadyExists: Exception raised when a key already exists in the cache and the user tries to set it again.
  • decorator: Module that exposes a decorator to cache function calls.

Examples

To create a new cache:

from cacheia import Cacheia
from cacheia_schemas import CachedValue


Cacheia.setup()
cache = Cacheia.get()
instance = CachedValue(key="key", value="value")
cache.cache(instance=instance)

To get all cached values:

from cacheia import Cacheia


Cacheia.setup()
cache = Cacheia.get()
for value in cache.get():
    print(value)

To get a value from the cache:

from cacheia import Cacheia


Cacheia.setup()
cache = Cacheia.get()
cached_value = cache.get_key("key")
print(cached_value)

To flush all values:

from cacheia import Cacheia


Cacheia.setup()
cache = Cacheia.get()
result = cache.flush()
print(result.deleted_count)

To flush some values:

from datetime import datetime
from cacheia import Cacheia


Cacheia.setup()
cache = Cacheia.get()

now = datetime.now().timestamp()
result = cache.flush(expires_range=(now - 100, now + 100))
print(result.deleted_count)

To flush a single key:

from cacheia import Cacheia


Cacheia.setup()
cache = Cacheia.get()

result = cache.flush_key(key="key")
print(result.deleted_count)

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

cacheia-1.0.0.post3.tar.gz (7.2 kB view hashes)

Uploaded Source

Built Distribution

cacheia-1.0.0.post3-py3-none-any.whl (6.5 kB view hashes)

Uploaded Python 3

Supported by

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