
Product
Socket Now Supports pylock.toml Files
Socket now supports pylock.toml, enabling secure, reproducible Python builds with advanced scanning and full alignment with PEP 751's new standard.
Supply Chain Security
Vulnerability
Quality
Maintenance
License
Unpopular package
QualityThis package is not very popular.
Found 1 instance in 1 package
Python cache decorator that uses Redis or KeyDB as storage. This is very handy for replicated apps (e.g. Kubernetes), AWS Lambda functions, and other stateless apps.
Features:
BaseModel
Limitations:
pip install redis_cached
Basic usage:
import asyncio
from redis_cached import Cache
cache = Cache()
@cache.cached(5)
async def get_user_data(user_id: int):
# expensive API call here
return {'user_id': user_id, 'name': 'John Doe'}
async def main():
user_data = await get_user_data(user_id=1) # result is cached for 5 seconds
# To invalidate the cache for the user with ID 1, pass the same kwargs:
await cache.invalidate_cache('get_user_data', user_id=1)
asyncio.run(main())
Optionally, add salt to cache_key_salt
to avoid clashing with the same-named functions in other modules or other apps that use the same Redis database.
You can also use your custom-configured async Redis instance with the cache.
import asyncio
from redis.asyncio.client import Redis
from redis_cached import Cache
custom_redis = Redis(
host='localhost',
port=6379,
db=0
)
cache = Cache(
cache_key_salt='qhDwh9Y',
redis_=custom_redis
)
@cache.cached(5)
async def get_user_data(user_id: int):
# expensive API call here
return {'user_id': user_id, 'name': 'John Doe'}
async def main():
user_data = await get_user_data(user_id=1) # cached
await cache.invalidate_cache('get_user_data', user_id=1) # invalidated
asyncio.run(main())
Contributions are welcome. Please refer to the maintenance readme for more details.
FAQs
Python cache decorator and other itils with support for Redis or KeyDB
We found that redis-cached demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Socket now supports pylock.toml, enabling secure, reproducible Python builds with advanced scanning and full alignment with PEP 751's new standard.
Security News
Research
Socket uncovered two npm packages that register hidden HTTP endpoints to delete all files on command.
Research
Security News
Malicious Ruby gems typosquat Fastlane plugins to steal Telegram bot tokens, messages, and files, exploiting demand after Vietnam’s Telegram ban.