Opened 14 years ago

Closed 14 years ago

#11503 closed (duplicate)

Cache backend should expose a flush method

Reported by: andrewfong Owned by: andrewfong
Component: Core (Cache system) Version: dev
Severity: Keywords: flush
Cc: david@…, chris@… Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

The low level cache interface (django.core.cache.cache) should expose a method to flush out the entire cache. The primary use of this, off the top of my head, would be to make it easier to test caching by flushing out everything in between tests, although there are probably other use cases as well.

Currently, in order to do this, you have to rely on different methods for each backend. For example, with the memcached backend, you call cache._cache.flush_all(), whereas with locmem, you set cache._cache = {}. Having backends implement a flush method would make this consistent across all supported backend options.

Attachments (2)

patch.diff (9.1 KB) - added by andrewfong 14 years ago.
Exposes a flush method that clears the cache for each backend + tests. Also, since culling and flushing are related (e.g. when the cull frequency is 0), I refactored some of the culling code to use the flush method instead. Accordingly, I've added tests to make sure culling is still working correctly.
11503-docs.diff (741 bytes) - added by David Reynolds 14 years ago.
Tiny documentation patch describing .flush()

Download all attachments as: .zip

Change History (9)

comment:1 Changed 14 years ago by andrewfong

Owner: changed from nobody to andrewfong
Status: newassigned

comment:2 Changed 14 years ago by Russell Keith-Magee

Triage Stage: UnreviewedAccepted

Changed 14 years ago by andrewfong

Attachment: patch.diff added

Exposes a flush method that clears the cache for each backend + tests. Also, since culling and flushing are related (e.g. when the cull frequency is 0), I refactored some of the culling code to use the flush method instead. Accordingly, I've added tests to make sure culling is still working correctly.

comment:3 Changed 14 years ago by andrewfong

Has patch: set
Needs documentation: set

Changed 14 years ago by David Reynolds

Attachment: 11503-docs.diff added

Tiny documentation patch describing .flush()

comment:4 Changed 14 years ago by David Reynolds

Needs documentation: unset

Added a quick patch with some documentation for flush()

comment:5 Changed 14 years ago by David Reynolds

Cc: david@… added

comment:6 Changed 14 years ago by Chris Adams

Cc: chris@… added

comment:7 Changed 14 years ago by anonymous

Resolution: duplicate
Status: assignedclosed

#12671 added a clear() method to the cache backends.

Note: See TracTickets for help on using tickets.
Back to Top