0

I'm trying to cache the request.POST dict using the low-level cache API, but it seems to not be working. Instead of the cached dict I get the None value.

Here's what I tried:

print cache.get('forms_data') # It is None
education_formset = Education(
    request.POST or cache.get('forms_data') or None, prefix='education')

if education_formset.is_valid():
    if 'view' in request.POST:
        cache.set('forms_data', request.POST, 600)

Settings:

CACHES = {
    'default': {
        'BACKEND': 'django.core.cache.backends.memcached.MemcachedCache',
        'LOCATION': 'unix:/tmp/memcached.sock',
    }
}

There were no exceptions when running the code.

Could it be something wrong with the settings or with the unix memcached.sock?

I159
  • 29,741
  • 31
  • 97
  • 132
  • 1
    Your interactive mode example is correct, `cache.set` return nothing (`None`). Try `cache.get` in interactive mode. – DrTyrsa Nov 01 '11 at 09:43
  • Thanks, it's works. I'm removing the incorrect side of the issue. – I159 Nov 01 '11 at 09:54

1 Answers1

0

As DrTyrsa points out in the comments, cache.set returns None.

However, I can't work out what you are trying to achieve here. The cache is global: it's the same for all users of your site. What you're doing here is caching one user's POST values, then retrieving them for all other users. I doubt very much that is what you intend.

If you want to store a user's submissions, keep them in the session.

Daniel Roseman
  • 588,541
  • 66
  • 880
  • 895