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
Release history Release notifications | RSS feed
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)
Built Distribution
Close
Hashes for cacheia-1.0.0.post3-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a62c785ef1f141cc601b45f700886c027b413c099c90c5123ff738013ece0f13 |
|
MD5 | 62b2dd9fa9f0f51326ff46482ae8b91f |
|
BLAKE2b-256 | b441533660481096881fa94d9ecb646a4aa1d7916052431cadfd5ce375394b3a |