Caching utilities with Redis and Memory providers for Smart Platform
Project description
Smart Cache
Caching utilities with Redis and Memory providers for Smart Platform.
Features
- Multiple Providers: Redis and in-memory caching
- Async/Await: Full async support
- TTL Support: Time-based expiration
- Decorators: Easy function caching
- Type Safe: Full type hints
Installation
pip install smart-cache
Usage
Memory Cache
from mehdashti_cache import MemoryCache, cached
# Initialize cache
cache = MemoryCache(cleanup_interval=60)
await cache.start_cleanup()
# Use directly
await cache.set("user:1", {"name": "John"}, ttl=300)
user = await cache.get("user:1")
# Use as decorator
@cached(cache, ttl=300)
async def get_user(user_id: int):
# Expensive operation
return await db.get_user(user_id)
Redis Cache
from mehdashti_cache import RedisCache, cached
# Initialize cache
cache = RedisCache(redis_url="redis://localhost:6379/0")
# Use directly
await cache.set("user:1", {"name": "John"}, ttl=300)
user = await cache.get("user:1")
# Use as decorator
@cached(cache, ttl=300, key_prefix="user")
async def get_user(user_id: int):
return await db.get_user(user_id)
API
CacheProvider
Base interface for all cache providers.
get(key): Get valueset(key, value, ttl): Set valuedelete(key): Delete valueexists(key): Check if existsclear(): Clear allget_many(keys): Get multiple valuesset_many(items, ttl): Set multiple valuesdelete_many(keys): Delete multiple valuesget_ttl(key): Get remaining TTL
License
MIT
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
mehdashti_cache-0.1.0.tar.gz
(5.4 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file mehdashti_cache-0.1.0.tar.gz.
File metadata
- Download URL: mehdashti_cache-0.1.0.tar.gz
- Upload date:
- Size: 5.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.9.11 {"installer":{"name":"uv","version":"0.9.11"},"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":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7581b4419eb273cd365dfcb974c2dad1c838ae77bb5d205b6272596ef12733fc
|
|
| MD5 |
dce511b314a28067ff731f901831eef7
|
|
| BLAKE2b-256 |
ffbf40851d83aa4dcf3fb68406846f2f7664d113b37b5874cda97db54a2a72c5
|
File details
Details for the file mehdashti_cache-0.1.0-py3-none-any.whl.
File metadata
- Download URL: mehdashti_cache-0.1.0-py3-none-any.whl
- Upload date:
- Size: 7.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.9.11 {"installer":{"name":"uv","version":"0.9.11"},"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":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2f2f8cd073a7d5e9d4bc47667bf15460930f31ca99bbad9a6f4c027991171f75
|
|
| MD5 |
08e5516dc4e59d42c8bf920eadbbe704
|
|
| BLAKE2b-256 |
04129ebde812cc195e4a0554b92b9abab1d3f69b552a151939f7255c9629b1fa
|