Skip to content

Allow passing serializer as a class parameter. #136

@g-abello

Description

@g-abello

Following the discussion in #11 and the improvement done in #63, where custom serializers were added for each cache backend. I think that it would be very nice to have a few generic serializers (Pickle, JSON, etc) that could be passed as a parameter when initialising the cache backends.

Something that would look like:

from cachelib import FileSystemCache, RedisCache
from cachelib.serializers import JsonSerializer, PickleSerializer

redis_cache = RedisCache(serializer=JsonSerializer)
file_cache = FileSystemCache(serializer=PickleSerializer)

Each backend cache would obviously have a default serializer for backwards compatibility.

This would allow using more secure serialization alternatives than Pickle.
The ultimate goal that I would like to achieve would be to be able to use a custom serializer with the Flask-Caching library.

I could try to work out a solution for this and submit a PR if you think this approach would make sense.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions