Note: This release will invalidate your caches because we changed the default hash_method from hashlib.md5 to hashlib.sha256. This can be changed back via CACHE_HASH_METHOD if you wish to still use the old hash_method!
Added / Improved
- Specifying timeouts now also works with
datetime.timedelta. #266 - Add config option
CACHE_SERIALIZERto set the cachelib serializer the backend uses. #209 - cachelib backends can now be configured directly via
CACHE_TYPE="cachelib.ValkeyCache. #668 - Send Signals for cache hits and misses. #237 and #667
- Add
Cache.delete_cached()and extendmake_cache_key()withpathandquery_argsarguments to make deleting views decorated withcached(query_string=True)possible. #243 - Add
CACHE_HASH_METHODto set the hash method used for the cache keys of@cachedand@memoize. - Add an
is_staleoption to@cachedand@memoize. It is called on a cache hit with the cached value. Unlikeforced_updateit uses the value itself to check whether the cache is stale. Can be used in combination withforced_update#392 @cachedand@memoizenow preserve the wrapped function's signature and exposeuncached,cache_timeout,make_cache_keydelete_memoizedto type checkers.- Add
CACHE_FILE_HASH_METHODconfig option toFileSystemCacheto allow using a different hash function for cache keys. #660 - Add
pool_sizeandpool_blockingto makeMemcachedCachebackends thread-safe. #663 - Document that
CACHE_REDIS_HOSTaccepts an already createdredis.Redisclient instead of a host name, which allows sharing a connection pool with other extensions and the application. #629 - Clarify docs about decorator order regarding
@staticmethodand@classmethodwhen memoizing. #440 - Modify
SimpleCachedocs as it's now thread-safe using anRLockfor all operations. #663
Changed
- Drop support for Python 3.10 and require cachelib 0.17.0+
- Remove the deprecated lowercase
CACHE_TYPEnames (null,simple,filesystem,redis,redissentinel,rediscluster,uwsgi,memcached,gaememcached,saslmemcachedandspreadsaslmemcached) - Use
hashlib.sha256instead ofhashlib.md5for hashing the cache keys. This changes the generated keys, so entries cached by an earlier version become obsolete. If you wish to still use hashlib.md5 set the configCACHE_HASH_METHOD = hashlib.md5. #563 @cachedand@memoizenow go through the publicCacheproxy methods (get,set,has,delete,delete_many,get_manyandset_many) instead of calling the backend directly. #417CACHE_IGNORE_ERRORSis now used by every backend instead of onlySimpleCacheandFileSystemCache.- The
delete_manymethod is now used from cachelib. A key that does not exist counts as deleted, and withCACHE_IGNORE_ERRORSset toFalseaRuntimeErroris raised if the key could not be deleted. - Call
@memoizeforced_updatecallbacks once per decorated function call instead of once while making the key and again before cache lookup. #387 @cachednow caches anHTTPExceptionraised by the view (i.e. throughabort()). This exception will now be re-raises on a cache hit. Useresponse_filter, to keep the exception out of the cache. #444- The
{% cache %}Jinja tag no longer propagates backend errors. If the cache is unavailable, the block is rendered normally instead of raising, matching the existing behavior of@memoize. #564 #565
Fixed
- Include
key_prefixwhen building@cached(query_string=True)cache keys. #302 - Fix a
@memoizecache-key collision when a parameter has a falsy default (e.g.0,"",False): calling with the default was keyed the same as passingNone, returning the wrong cached result. #656 - Fix
@cached(response_hit_indication=True)appending a newafter_requestfunction to the app on every request. - Fix a view returning an iterator of strings, for example when using
flask.stream_templateit previously returned a list of JSON strings instead of the rendered template. #511 - Fix
__caching_id__never being usable.@memoizesilently ignored that and ran the function uncached. delete_memoizednow takes the instance from a bound method, socache.delete_memoized(obj.method, 1)deletes the cache forobj.method(1)instead of silently deleting nothing. The current behaviour by passing the instance keeps working as well. #554- Fix
@memoizeinvalidating a function's entire cache by not updating the memoize version key's timeout. It is now refreshed each time an entry is written, with that entry's own timeout. #531
New Contributors
- @uttam12331 made their first contribution in #656
- @deepakganesh78 made their first contribution in #655
- @nightcityblade made their first contribution in #665
- @dzpt made their first contribution in #565
- @aoright made their first contribution in #672
Full Changelog: v2.4.1...v2.5.0