keithxm23
keithxm23

Reputation: 1280

Django How to know if queryset is cached or not? using johnnycache

I just discovered johnnycache and it looks awesome. I pip-installed it and added the few lines of code to my settings just as the documentation instructed as follows.

CACHES = {
    'default': {
        'BACKEND': 'johnny.backends.memcached.MemcachedCache',
        'LOCATION': '127.0.0.1:8000',
        'JOHNNY_CACHE': True,
    }
}
JOHNNY_MIDDLEWARE_KEY_PREFIX = 'jc_efl'

and the Middleware settings..

MIDDLEWARE_CLASSES = (
    'johnny.middleware.LocalStoreClearMiddleware',
    'johnny.middleware.QueryCacheMiddleware',
... }

I loaded my site in my browser and it runs fine and there isn't any noticeable difference in load-times.

I want to know how can I know if my retrieved queries are actually coming from the cache or not.

I looked up on Google and SO and a lot is mentioned about view/template caching where they use the commented-timestamp method of getting it done. But I believe, that does not apply here.

Please help!

Upvotes: 2

Views: 1498

Answers (2)

Antonis Christofides
Antonis Christofides

Reputation: 6949

You can also use the Django Debug Toolbar (DDT) to see the queries run by each request. If the DDT shows queries being run, it means they are cache misses.

Upvotes: 0

nichol s
nichol s

Reputation: 793

I was just searching for the same thing. I think they intend for you to use the signals

johnny.cache.signals.qc_hit - fired after a cache hit

and

johnny.cache.signals.qc_miss - fired after a cache miss

from johnny cache docs

Upvotes: 1

Related Questions