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 details)

Uploaded Source

Built Distribution

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

Uploaded Python 3

File details

Details for the file cacheia-1.0.0.post3.tar.gz.

File metadata

  • Download URL: cacheia-1.0.0.post3.tar.gz
  • Upload date:
  • Size: 7.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.4

File hashes

Hashes for cacheia-1.0.0.post3.tar.gz
Algorithm Hash digest
SHA256 89d39006bd0c34200040841c64522f992456417c6e5ef4a81b555fa78e81965a
MD5 04247c7903d4cebc6be73a3489ef754f
BLAKE2b-256 519f5b5fffd2f5fcc9f982088ce0f8ca3ee7a63ae45e9ae6dbec06068aa9f6a7

See more details on using hashes here.

File details

Details for the file cacheia-1.0.0.post3-py3-none-any.whl.

File metadata

File hashes

Hashes for cacheia-1.0.0.post3-py3-none-any.whl
Algorithm Hash digest
SHA256 a62c785ef1f141cc601b45f700886c027b413c099c90c5123ff738013ece0f13
MD5 62b2dd9fa9f0f51326ff46482ae8b91f
BLAKE2b-256 b441533660481096881fa94d9ecb646a4aa1d7916052431cadfd5ce375394b3a

See more details on using hashes here.

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