Code

Opened 5 years ago

Closed 4 years ago

#11503 closed (duplicate)

Cache backend should expose a flush method

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

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 5 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 DavidReynolds 5 years ago.
Tiny documentation patch describing .flush()

Download all attachments as: .zip

Change History (9)

comment:1 Changed 5 years ago by andrewfong

  • Owner changed from nobody to andrewfong
  • Status changed from new to assigned

comment:2 Changed 5 years ago by russellm

  • Triage Stage changed from Unreviewed to Accepted

Changed 5 years ago by andrewfong

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 5 years ago by andrewfong

  • Has patch set
  • Needs documentation set

Changed 5 years ago by DavidReynolds

Tiny documentation patch describing .flush()

comment:4 Changed 5 years ago by DavidReynolds

  • Needs documentation unset

Added a quick patch with some documentation for flush()

comment:5 Changed 5 years ago by DavidReynolds

  • Cc david@… added

comment:6 Changed 5 years ago by acdha

  • Cc chris@… added

comment:7 Changed 4 years ago by anonymous

  • Resolution set to duplicate
  • Status changed from assigned to closed

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

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.