Opened 3 years ago

Closed 2 years ago

#22085 closed New feature (fixed)

Allow CACHES['cache']['TIMEOUT']: None to set a non-expiring timeout by default.

Reported by: honi Owned by: zr
Component: Core (Cache system) Version: 1.6
Severity: Normal Keywords: cache timeout
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: yes
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no


BaseCache will try to cast the default timeout to int, which will throw a TypeError if timeout is None, thus setting default_timeout to 300.

Relevant lines here:

Django 1.6 made some changes to allow setting the cache timeout to None for non expiring keys, as described here:

Explicitly passing None in cache.set works as expected. It does not work if set in CACHE dict in django settings.

This currently does not work for me (keys expire in 300 seconds):

    'default': {
        'BACKEND': 'django.core.cache.backends.locmem.LocMemCache',
        'LOCATION': 'unique-snowflake',
        'TIMEOUT': None

Change History (6)

comment:1 Changed 3 years ago by timo

  • Easy pickings unset
  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Summary changed from TIMEOUT==None defined in CACHE settings is discarded by BaseCache init code to Allow CACHES['cache']['TIMEOUT']: None to set a non-expiring timeout by default.
  • Triage Stage changed from Unreviewed to Accepted
  • Type changed from Bug to New feature

This is outside of the scope of the changes in Django 1.6 so it's really more of a feature request than a bug.

comment:2 Changed 3 years ago by zr

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

comment:3 Changed 3 years ago by zr

I have implemented this feature and written several tests for it.

The pull request is here:

comment:4 Changed 3 years ago by zr

  • Has patch set

comment:5 Changed 2 years ago by timo

  • Needs documentation set

The patch needs to include an update to the documentation and a mention in the release notes.

comment:6 Changed 2 years ago by Baptiste Mispelon <bmispelon@…>

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

In 6fe22b30e007b7ac49eae48a53e7ba0a4ee79a4b:

Fixed #22085 -- Added a feature for setting non-expiring keys as the default.

This feature allows the default TIMEOUT Cache argument to be set to None,
so that cache instances can set a non-expiring key as the default,
instead of using the default value of 5 minutes.

Previously, this was possible only by passing None as an argument to
the set() method of objects of type BaseCache (and subtypes).

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