[Django] #24402: Missing support for rollback in django.core.cache

5 views
Skip to first unread message

Django

unread,
Feb 24, 2015, 5:06:41 AM2/24/15
to django-...@googlegroups.com
#24402: Missing support for rollback in django.core.cache
-------------------------------------+--------------------
Reporter: Tuttle | Owner: nobody
Type: New feature | Status: new
Component: Core (Cache system) | Version:
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+--------------------
Tried unsuccessfully to find existing ticket for this, so starting an idea
discussion.

In my project, I use `memcached` via `django.core.cache` to cache data
resulting from some ORM operations. But when the database rolls back, the
memcache is kept in the wrong state.

Currently I'm adding another layer with local dict (which has some speed
improvements effects):

{{{#!python
class DeferredMemcache(object):
def __init__(self):
from django.core import cache # Importing this way so
debug_toolbar can patch it later.

self.real_cache = cache.cache
self.local_cache = {}

def get(self, key, default=None):
try:
value, deadline = self.local_cache[key]
except KeyError:
return self.real_cache.get(key, default)
else:
return value if deadline > time.time() else default

def set(self, key, value, timeout):
assert timeout > 0
self.local_cache[key] = value, timeout + time.time()

def commit(self):
for key, (value, deadline) in self.local_cache.iteritems():
timeout = deadline - time.time()
if timeout >= 0:
self.real_cache.set(key, value, timeout)

self.local_cache.clear()
}}}

What do you think about adding some support for cache rollback in Django?

--
Ticket URL: <https://code.djangoproject.com/ticket/24402>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Feb 24, 2015, 9:04:06 AM2/24/15
to django-...@googlegroups.com
#24402: Missing support for rollback in django.core.cache
-------------------------------------+-------------------------------------

Reporter: Tuttle | Owner: nobody
Type: New feature | Status: new
Component: Core (Cache system) | Version:
Severity: Normal | Resolution:
Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by timgraham):

* needs_better_patch: => 0
* needs_tests: => 0
* needs_docs: => 0


Comment:

Could you please open a discussion on the DevelopersMailingList to get
feedback on the idea?

--
Ticket URL: <https://code.djangoproject.com/ticket/24402#comment:1>

Django

unread,
Feb 24, 2015, 11:14:08 AM2/24/15
to django-...@googlegroups.com
#24402: Missing support for rollback in django.core.cache
-------------------------------------+-------------------------------------

Reporter: Tuttle | Owner: nobody
Type: New feature | Status: new
Component: Core (Cache system) | Version:
Severity: Normal | Resolution:
Keywords: | Triage Stage:
| Unreviewed

Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by aaugustin):

I believe this is a duplicate of #21803.

--
Ticket URL: <https://code.djangoproject.com/ticket/24402#comment:2>

Django

unread,
Mar 2, 2015, 10:32:59 AM3/2/15
to django-...@googlegroups.com
#24402: Missing support for rollback in django.core.cache
-------------------------------------+-------------------------------------
Reporter: Tuttle | Owner: nobody
Type: New feature | Status: closed

Component: Core (Cache system) | Version:
Severity: Normal | Resolution: duplicate
Keywords: | Triage Stage:
| Unreviewed

Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by timgraham):

* status: new => closed
* resolution: => duplicate


--
Ticket URL: <https://code.djangoproject.com/ticket/24402#comment:3>

Reply all
Reply to author
Forward
0 new messages