1

I'm aware of Johnny cache's MAN_IN_BLACKLIST and JOHNNY_TABLE_BLACKLIST. Is there a way to specify the reverse? That is specify only the tables that need to be cached? I want to do this for the simple reason that we have over 200 tables in the application and I want to cache a few and don't want my MAN_IN_BLACKLIST to be really huge.

Thanks,

Charles
  • 50,943
  • 13
  • 104
  • 142
ksrini
  • 1,412
  • 2
  • 19
  • 33

2 Answers2

1

Instead of writing tables explicitly, I'm afraid you need to hack johnny/cache.py, mainly lines contains blacklist_match. The easiest way is to modify the function blacklist_match directly:

# set WHITELIST in johnny/settings.py, just as BLACKLIST
WHITELIST = getattr(settings, 'MAN_IN_WHITELIST',
            getattr(settings, 'JOHNNY_TABLE_WHITELIST', []))
WHITELIST = set(WHITELIST)

def blacklist_match(*tables):
    return not WHITELIST.issuperset(tables) or \
           bool(settings.BLACKLIST.intersection(tables))
okm
  • 23,575
  • 5
  • 83
  • 90
  • OK, Thanks. I also see that if I fire a raw select query using the django db connection/cursor it doesn't seem to cache the result. Is that by design? Or is it possible to cache those results as well? – ksrini May 11 '12 at 09:22
  • @ksrini Yes, Johnny monkey-patches sqlcompiler for normal Query, and do not wrap `QuerySet.raw()` and `db.cursor()`. – okm May 11 '12 at 10:10
0

As of version 1.4 Johnny Cache actually supports whitelists. Add JOHNNY_TABLE_WHITELIST to your settings and assign it the list of tables you want to be cached, e.g.:

JOHNNY_TABLE_WHITELIST = ['appname_tablename', 'someotherapp_differenttable']

source

ibloat
  • 1
  • 1