pallets-eco/flask-caching

Rewrite the redish cache

helioascorreia opened this issue · 0 comments

On the previous version (1.10.1) i've overwrite the RedisCache class to remove the ! from the json like this.

import pickle

from flask_caching.backends.rediscache import RedisCache as BaseRedisCache


class RedisCache(BaseRedisCache):

    def dump_object(self, value):
        """Dumps an object into a string for redis.  By default it serializes
        integers as regular string and pickle dumps everything else.
        """
        return pickle.dumps(value)

    def load_object(self, value):
        """The reversal of :meth:`dump_object`.  This might be called with
        None.
        """
        if value is None:
            return None
        return pickle.loads(value)

and on the settings I put this

CACHES = {
    "default": {
        "CACHE_TYPE": "NullCache",
    },
    "shared_user": {
        "CACHE_TYPE": "core_lib.utils.flask.cache.backends.RedisCache",
        "CACHE_REDIS_URL": REDIS_URL,
        "CACHE_KEY_PREFIX": "shared_user:1:",
    },
}

the corelib it the path to the overwrited class

In the previous version this works fine.
If there is a better way to remove ! I can test, if not I need this to work with other projects

Environment:

  • Python version: 3.8
  • Flask-Caching version: 2.0.0