flask-caching icon indicating copy to clipboard operation
flask-caching copied to clipboard

Use both key_prefix and query_string to form the cache key

Open Ashwin-shankar50 opened this issue 4 years ago • 1 comments

Version referred - 1.10.1

Description

In current implementation cached function under the Cache class considers either query_string parameter or key_prefix parameter to build the cache key

It can be enhanced and made to consider both options together to build the cache key.

Explanation

If the cache key needs to be built like,

Expectation - Expected format - flask_cache_<key_prefix>/<request_url><query_string_hash> Example - flask_cache_user_managemen//api/v1/users52440c19267b11c4bbe10e97c6e45885

Current possibilities -

Format 1 - flask_cache_<key_prefix>/<request_url> Example - flask_cache_user_management//api/v1/users

Format 1 - flask_cache_<request_url><query_string_hash> Example - flask_cache_/api/v1/users52440c19267b11c4bbe10e97c6e45885

Ashwin-shankar50 avatar Dec 03 '21 08:12 Ashwin-shankar50

Agreed! Not just a feature request but arguably a bug fix, or at least prevention. There's currently no indication that query_string silently overrides key_prefix and ignores it, which is an unpleasant surprise.

(Thank you for maintaining flask-caching @northernSage et al, it's great!)

snarfed avatar Nov 08 '23 21:11 snarfed