Opened 11 years ago

Closed 11 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: Rigel Di Scala
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

Description

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: https://github.com/django/django/blob/master/django/core/cache/backends/base.py#L54-L59

Django 1.6 made some changes to allow setting the cache timeout to None for non expiring keys, as described here: https://github.com/django/django/blob/master/django/core/cache/backends/base.py#L54-L59

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):

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

Change History (6)

comment:1 by Tim Graham, 11 years ago

Easy pickings: unset
Summary: TIMEOUT==None defined in CACHE settings is discarded by BaseCache init codeAllow CACHES['cache']['TIMEOUT']: None to set a non-expiring timeout by default.
Triage Stage: UnreviewedAccepted
Type: BugNew 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 by Rigel Di Scala, 11 years ago

Owner: changed from nobody to Rigel Di Scala
Status: newassigned

comment:3 by Rigel Di Scala, 11 years ago

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

The pull request is here: https://github.com/django/django/pull/2365

comment:4 by Rigel Di Scala, 11 years ago

Has patch: set

comment:5 by Tim Graham, 11 years ago

Needs documentation: set

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

comment:6 by Baptiste Mispelon <bmispelon@…>, 11 years ago

Resolution: fixed
Status: assignedclosed

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