4

In my settings.py I have:

CACHES = {
    'default': {
        'BACKEND': 'django.core.cache.backends.db.DatabaseCache',
        'LOCATION': 'ws_cache_table',
        'TIMEOUT': '3000000',
        'OPTIONS': {
            'MAX_ENTRIES': 10000000
        }
    }
}

But if I do this in python manage.py shell:

from django.core.cache import cache
print type(cache)

I'm getting:

django.core.cache.backends.locmem.LocMemCache

Why!??? Now I can't clear my cache...

To prove my configuration is corect I can do:

from django.conf import settings
conf = settings.CACHES.get('default', None)

And I'm getting:

{'BACKEND': 'django.core.cache.backends.db.DatabaseCache',
 'LOCATION': 'ws_cache_table',
 'OPTIONS': {'MAX_ENTRIES': 10000000},
 'TIMEOUT': '3000000'}

It looks like get_cache method is called before CACHES is defined...

mnowotka
  • 16,430
  • 18
  • 88
  • 134
  • 1
    Possibly you are accessing the `django.core.cache.cache` from code that is reachable in settings? – Maciej Gol Sep 25 '13 at 16:28
  • which Django version ? – bruno desthuilliers Sep 25 '13 at 16:35
  • Are you sure no other 'local' settings is replacing the `CACHES` setting? If you manually call `django.core.cache.get_cache('default')`, what do you obtain? – augustomen Sep 25 '13 at 16:48
  • @kroolik - I don't understand, can you explain? – mnowotka Sep 25 '13 at 18:02
  • @brunodesthuilliers - 1.4 – mnowotka Sep 25 '13 at 18:03
  • Do you import or use any code in your settings files that directly or indirectly uses or imports `django.core.cache`? – Maciej Gol Sep 25 '13 at 19:13
  • What i mean is, do you do something like `from myproj.myapp.module import MyName`, and by any chance `module` imports something that imports `django.core.cache`. – Maciej Gol Sep 26 '13 at 05:58
  • @kroolik - I see your point and you are right - i had this in my settings and this caused the problem. But this has only uncovered the real problem have and the reason I was playing witm my settings and cache, please see here: http://stackoverflow.com/questions/19024127/django-cant-clear-databse-cache-on-oracle-backend – mnowotka Sep 26 '13 at 09:21

1 Answers1

0

First of all you should keep in mind that your local_settings.py would overwrite the settings.py.

Then you should watch out what cache daemon as backend is running, as there are different ones and depending what you run you need the respective specified option.

e.g. for memcached the local_settings.py would read:

CACHES = {
    'default': {
        'BACKEND': 'django.core.cache.backends.memcached.MemcachedCache',
        'LOCATION': '127.0.0.1:11211'
        'CACHE_TIME': '3600',
    }
}

whereas for locmem:

CACHES = {
    'default': {
        'BACKEND': 'django.core.cache.backends.locmem.LocMemCache'
        'LOCATION': '127.0.0.1:11211'
        'TIMEOUT': 3600'
    }
}
mcantsin
  • 124
  • 13