Skip to main content

redis based cache_clear() for lru_cache

Project description

lru_cache_pubsub_cache_clear

lru_cache_pubsub_cache_clear is a decorator to broadcast cache_clear() calls to lru_cache across multiple instances of an application. This allows for local cache access speed and redis-like centralized cache invalidation. Example:

from lru_cache_pubsub_cache_clear.decorators import lru_cache_pubsub_cache_clear
from django_redis import get_redis_connection


@lru_cache_pubsub_cache_clear(get_redis_connection=get_redis_connection,
                              channel_name='CHANNEL_CACHE_CLEAR')
@lru_cache(maxsize=1000000)
def get_data(key)
    ...
    return value

Here get_redis_connection is a callable which returns a redis connection (e.g. django_redis.get_redis_connection).

Then every time one of app instances calls get_data.cache_clear() it will be executed on all connected instances.

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

lru-cache-pubsub-cache-clear-0.0.9.tar.gz (1.9 kB view hashes)

Uploaded source

Built Distribution

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Huawei Huawei PSF Sponsor Microsoft Microsoft PSF Sponsor NVIDIA NVIDIA PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page