Commit Graph

212 Commits

Author SHA1 Message Date
Jeremy Lainé 2f33217ea2 Fixed #33361 -- Fixed Redis cache backend crash on booleans. 2021-12-14 07:16:30 +01:00
Arsa 17df72114e Fixed #33340 -- Fixed unquoted column names in queries used by DatabaseCache. 2021-12-09 11:16:04 +01:00
Ade Lee d10c7bfe56 Fixed #28401 -- Allowed hashlib.md5() calls to work with FIPS kernels.
md5 is not an approved algorithm in FIPS mode, and trying to instantiate
a hashlib.md5() will fail when the system is running in FIPS mode.

md5 is allowed when in a non-security context. There is a plan to add a
keyword parameter (usedforsecurity) to hashlib.md5() to annotate whether
or not the instance is being used in a security context.

In the case where it is not, the instantiation of md5 will be allowed.
See https://bugs.python.org/issue9216 for more details.

Some downstream python versions already support this parameter. To
support these versions, a new encapsulation of md5() has been added.
This encapsulation will pass through the usedforsecurity parameter in
the case where the parameter is supported, and strip it if it is not.

Co-authored-by: Mariusz Felisiak <felisiak.mariusz@gmail.com>
2021-10-12 08:58:27 +02:00
Mariusz Felisiak 05f3a6186e Refs #32193 -- Removed MemcachedCache per deprecation timeline. 2021-09-20 21:23:01 +02:00
Daniyal ec212c6616 Fixed #33012 -- Added Redis cache backend.
Thanks Carlton Gibson, Chris Jerdonek, David Smith, Keryn Knight,
Mariusz Felisiak, and Nick Pope for reviews and mentoring this
Google Summer of Code 2021 project.
2021-09-14 15:50:08 +02:00
Andrew-Chen-Wang 301a85a12f Fixed #32076 -- Added async methods to BaseCache.
This also makes DummyCache async-compatible.
2021-09-07 20:14:25 +02:00
Nick Pope 42dfa97e19 Fixed #33060 -- Added BaseCache.make_and_validate_key() hook.
This helper function reduces the amount of duplicated code and makes it
easier to ensure that we always validate the keys.
2021-09-07 11:59:59 +02:00
Nick Pope 4b82578a60 Refs #33060 -- Ensured cache backends validate keys.
The validate_key() function should be called after make_key() to ensure
that the validation is performed on the key that will actually be
stored in the cache.

Co-authored-by: Mariusz Felisiak <felisiak.mariusz@gmail.com>
2021-09-07 11:59:40 +02:00
Nick Pope 68b8eda788 Refs #33060 -- Added .make_key() in .touch() for dummy cache backend.
All cache operations should use make_key().
2021-09-03 10:36:14 +02:00
Mariusz Felisiak 93e06f2978
Refs #33061 -- Removed unnecessary BaseMemcachedCache.decr(). 2021-08-31 10:37:59 +02:00
Sondre Lillebø Gundersen 2c912c3488 Fixed #33061 -- Fixed handling nonexistent keys with negative deltas in incr()/decr() in memcached backends.
Thanks Chris Jerdonek for the review.
2021-08-31 07:34:53 +02:00
Michael Lissner 5a8e8f80bb Fixed #32772 -- Made database cache count size once per set. 2021-05-26 11:21:11 +02:00
Nick Pope d06c5b3581 Fixed #32366 -- Updated datetime module usage to recommended approach.
- Replaced datetime.utcnow() with datetime.now().
- Replaced datetime.utcfromtimestamp() with datetime.fromtimestamp().
- Replaced datetime.utctimetuple() with datetime.timetuple().
- Replaced calendar.timegm() and datetime.utctimetuple() with datetime.timestamp().
2021-05-12 11:08:41 +02:00
ecogels a0a5e0f4c8 Fixed #32705 -- Prevented database cache backend from checking .rowcount on closed cursor.
Co-authored-by: Mariusz Felisiak <felisiak.mariusz@gmail.com>
2021-05-05 12:41:59 +02:00
Nick Pope bb64b99b78 Fixed #29867 -- Added support for storing None value in caches.
Many of the cache operations make use of the default argument to the
.get() operation to determine whether the key was found in the cache.
The default value of the default argument is None, so this results in
these operations assuming that None is not stored in the cache when it
actually is. Adding a sentinel object solves this issue.

Unfortunately the unmaintained python-memcached library does not support
a default argument to .get(), so the previous behavior is preserved for
the deprecated MemcachedCache backend.
2020-12-17 09:57:21 +01:00
Abhishek Ghaskata 593829a5ab
Fixed typo in django/core/cache/backends/base.py docstring. 2020-12-15 07:05:02 +01:00
Mariusz Felisiak 5ce31d6a71
Fixed #32193 -- Deprecated MemcachedCache. 2020-12-09 21:27:32 +01:00
Nick Pope b4d46df5ca Fixed #29887 -- Added a cache backend for pymemcache. 2020-09-16 09:40:30 +02:00
Nick Pope a629139425 Refs #29887, Refs #24212 -- Added servers configuration hook for memcached backends.
The servers property can be overridden to allow memcached backends to
alter the server configuration prior to it being passed to instantiate
the client. This allows avoidance of documentation for per-backend
differences, e.g. stripping the 'unix:' prefix for pylibmc.
2020-09-02 08:51:17 +02:00
Nick Pope cc1f2c6a19 Refs #29887 -- Simplified memcached client instantiation. 2020-09-01 10:51:00 +02:00
Mariusz Felisiak 1853724aca Fixed CVE-2020-24584 -- Fixed permission escalation in intermediate-level directories of the file system cache on Python 3.7+. 2020-09-01 09:17:23 +02:00
Nick Pope b5acb9db75 Fixed #31907 -- Fixed missing validate_key() calls in cache backends. 2020-08-24 09:41:21 +02:00
Nick Pope e2013b260a Refs #29887, #27480 -- Moved touch() to BaseMemcachedCache. 2020-08-20 09:00:21 +02:00
Nick Pope 0cb0d59b23 Fixed comments related to nonexistent keys for incr()/decr() in memcached backends. 2020-08-20 08:58:50 +02:00
Guillermo Bonvehí f386454d13 Fixed #31728 -- Fixed cache culling when no key is found for deletion.
DatabaseCache._cull implementation could fail if no key was found to
perform a deletion in the table. This prevented the new cache key/value
from being correctly added.
2020-06-22 06:29:35 +02:00
Mariusz Felisiak 926148ef01
Fixed #31654 -- Fixed cache key validation messages. 2020-06-05 07:21:52 +02:00
Dan Palmer 2c82414914 Fixed CVE-2020-13254 -- Enforced cache key validation in memcached backends. 2020-06-03 09:24:26 +02:00
daniel a rios efc3e32d6d Fixed #30759 -- Made cache.delete() return whether it succeeded.
Thanks Simon Charette for the review.
2019-11-14 11:14:11 +01:00
Jon Dufresne 8b3f1c35dd Removed unnecessary assignments in various code. 2019-04-24 13:09:29 +02:00
Jakub Szafrański 0104b5a417 Fixed #30181 -- Made cache.get() with default work correctly on PyLibMCCache if None is cached. 2019-02-14 19:57:38 -05:00
Jon Dufresne e42b788960 Simplified FileBasedCache.clear().
glob.glob1() ignores missing paths.
2019-02-08 18:23:41 -05:00
Jon Dufresne 290d8471bb Fixed #30147 -- Simplified directory creation with os.makedirs(..., exist_ok=True). 2019-01-31 12:53:36 -05:00
Tim Graham da5eb3d56c Refs #28370 -- Removed support for the context arg of Field.from_db_value() and Expression.convert_value().
Per deprecation timeline.
2019-01-17 10:52:19 -05:00
oliver abd0ad7681 Fixed #29626, #29584 -- Added optimized versions of get_many() and delete_many() for the db cache backend. 2018-08-17 15:13:09 -04:00
Simon Charette 37835883ad Fixed #29550 -- Eased overriding pickle.dumps() protocol in cache backends and session serializer. 2018-07-09 11:46:55 -04:00
Simon Charette 2d75509bcb Refs #27480 -- Moved FileBasedCache content writing logic to a method. 2018-07-09 11:46:03 -04:00
Christian Barcenas c9c6c16650 Fixed #20584 -- Fixed memcached's get_many() with single-use iterators.
Thanks Guyon Morée for the report.
2018-07-09 10:24:41 -04:00
Nicolas Noé 3246ad1065 Fixed #27480 -- Added cache.touch(). 2018-04-27 17:48:35 -04:00
Hajime Nakagami 8f75984c26 Quoted field names in cache db backend SQL.
On Firebird, 'value' is a reserved word and must be quoted.
2018-03-13 22:46:41 -04:00
Jon Dufresne 6a039800db Refs #27795 -- Replaced force_bytes() usage in django.core.cache. 2018-02-02 08:57:58 +01:00
Grant Jenks d38a3169a4 Fixed #28977 -- Changed local-memory cache to use LRU culling.
LRU culling turns every read into a kind of write to the cache: cache keys
are moved to the first position in the OrderedDict when they are retrieved.
The RWLock which permitted multiple readers while prioritizing a single
writer is obsolete since all accesses are now writes.
2018-01-24 12:26:19 -05:00
Дилян Палаузов d7b2aa24f7 Fixed #28982 -- Simplified code with and/or. 2018-01-03 20:12:23 -05:00
Nick Pope c68f66e014 Refs #23919 -- Replaced super() calls for old-style classes. 2017-12-07 09:10:32 -05:00
Adam Johnson acc989f037 Fixed #28760 -- Removed DummyCache's unnecessary get/set/delete_many(). 2017-10-31 12:16:09 -04:00
Adam Johnson abacd09f07 Refs #27318 -- Made DummyCache.set_many() return a list for consistency with other backends. 2017-10-30 12:13:17 -04:00
Daniel Tao 4d60261b2a Fixed #28601 -- Prevented cache.get_or_set() from caching None if default is a callable that returns None. 2017-10-10 09:20:34 -04:00
Tim Graham e47b56d791 Refs #20892 -- Removed support for passing pylibmc behavior settings as top-level attributes of CACHES['OPTIONS'].
Per deprecation timeline.
2017-09-22 12:51:17 -04:00
Tim Graham 6e4c6281db Reverted "Fixed #27818 -- Replaced try/except/pass with contextlib.suppress()."
This reverts commit 550cb3a365
because try/except performs better.
2017-09-07 08:16:21 -04:00
Olivier Tabone a027447f56 Fixed #27318 -- Made cache.set_many() return the list of failed keys. 2017-09-06 14:38:44 -04:00
Sergey Fedoseev 3633c2a045 Used dict comprehensions in BaseMemcachedCache.get_many() and set_many() for better readability. 2017-09-05 09:14:41 -04:00