- Trending Categories
- Data Structure
- Operating System
- C Programming
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to compress Python objects before saving to cache?
We need sometimes to compress Python objects (list, dictionary, string, etc) before saving them to cache and decompress after reading from cache.
Firstly we need to be sure we need to compress the objects. We should check if the data structures/objects are too big just to fit uncompressed in the cache. There is going to be an overhead for compression/decompression, that we have to tradeoff with the gains made by caching in the first place.
If we really need compression, then we probably want to use zlib.
If we are going to use zlib, we might want to experiment with the different compression levels available in the compress method, to balance CPU time vs compression levels:
Compresses the data in string, returning a string contained compressed data. level is an integer from 1 to 9 controlling the level of compression; 1 is fastest and produces the least compression, 9 is slowest and produces the most. The default value is 6. Raises the error exception if any error occurs.
- How to Compress files with ZIPFILE module in Python.
- How to find all objects created before specified Date in MongoDB?
- How to compress and un-compress the data of a file in Java?
- How we can compress large Python files?
- How to access Python objects within objects in Python?
- How to compress a file in Java?
- Best Way to compress mysqldump?
- How to un-compress a file in Java?
- LFU Cache in Python
- How to cache query results in Oracle?
- Compress The Schedule to Hit The Target
- Program to implement Least Frequently Used Cache in Python
- How to create class objects in Python?
- Generating a movie from Python without saving individual frames to files