Django Johnny cache - include tables instead of exclude using MAN_IN_BLACKLIST?
-
07-06-2021 - |
Вопрос
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,
Решение
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))
Другие советы
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']
Не связан с StackOverflow