Installation and Setup
Installation
To install:
Initialization (working with in-memory cache or redis
)
To start working with it, you'll have to initialize it using init_cachify
:
prefix='_PYC_'
as a cache key prefix (you can set it to whatever you like if needed)
If you want to use Redis:
from py_cachify import init_cachify
from redis.asyncio import from_url as async_from_url
from redis import from_url
init_cachify(sync_client=from_url(redis_url), async_clien=async_from_url(async_redis_client))
Once initialized you can use everything that the library provides straight up without being worried about managing the cache yourself.
If you forgot to call init_cachify
the CachifyInitError
will be raised during runtime.
See Examples.
Working with a different cache backend
If you want to use any other backend cache provider like for example memcached
,
you'll probably have to provide a small wrapper around its client to match the py-cachify
's signature.
To make it easier you can subclass the provided client's protocols.