3

I'm trying to use django-cache-machine to cache queries within my application, but I want to use Redis as a backend. The docs don't really explain how to do this, yet the repository is filled with Redis references, so I'm pretty sure it's possible. I want to make sure I do it right though, so I'm wondering if anyone has any experience with configuring this and maybe more importantly, knows if there are any caveats?

2 Answers 2

3

In your settings set:

CACHE_MACHINE_USE_REDIS = True

REDIS_BACKEND = redis://127.0.0.1:6379?socket_timeout=0.1

https://github.com/jbalogh/django-cache-machine/blob/master/caching/invalidation.py#L187 https://github.com/jbalogh/django-cache-machine/blob/master/caching/invalidation.py#L213

Sign up to request clarification or add additional context in comments.

1 Comment

Please note, when setting CACHE_MACHINE_USE_REDIS = True, django-cache-machine doesn't actually use Redis to cache your model objects, so you still need memcached configured. It only uses Redis to store and manipulate flush lists.
-1

I have a little experience in my project, a report system that generate tables from about 50 million records.

The database is Mysql and I could show my settings and models FYI.

settings:

    # cache machine
CACHES = {
    'default': {
        'BACKEND': 'caching.backends.memcached.MemcachedCache',
        'LOCATION': [
            '127.0.0.1:11211',
        ],
        'PREFIX': 'report:',
    },
}
CACHE_COUNT_TIMEOUT = 60 * 24  # one day
CACHE_EMPTY_QUERYSETS = True

models:

class App(**CachingMixin**, models.Model):
    **objects = CachingManager()**

    name = models.CharField(max_length=64,
                            default='')

Note that cache-machine works fine for query_set.filter and count, not good for query_set.annotate or aggregate. Of course do not forget launch your memcache client first.

And when running you can see cache-machine logs in your django*.log to tell you hit or miss cache.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.