Skip to main content
This is a pre-production deployment of Warehouse. Changes made here affect the production instance of PyPI (pypi.python.org).
Help us improve Python packaging - Donate today!

A collection of caching utilities.

Project Description

A hierarchy of classes to provide caching functionality with minimal fuss.

When using the cache, just use the fetch method. This will pull from the cache if it’s present and not expired otherwise will use ‘fetch_from_source’.

Cache

Abstract class. Not expected to be used. Provides the methods needed by subclasses provided by the package.

Methods that need to be implemented in the concrete class:
key fetch_from_source cache fetch_from_cache_by_key delete_by_key expiry_time
Optional:
cook

BaseMemoryClass

Abstract class.

Methods that must be implemented in concrete class:
key fetch_from_source calculate_expiry
Optional:
cook

SimpleMemoryClass

Abstract class.

Methods that must be implemented in concrete class:
key fetch_from_source
Optinal:
cook

BaseHttpMemoryCache

Abstract class.

Caches requests objects or objects generated from requests.

TODO: Improve expiry calculations. Currently only uses max age.

Methods that must be implemented in concrete class:
key fetch_from_source get_request_for_item (if caching objects generated from request objects)
Optinal:
cook

HttpMemoryCache

Concrete class.

Uses the url string as the key. Uses requests.get as fetch_from_source.

Use: Instantiate and use instance.fetch(url) to fetch from the cache or source.

BinaryFileCache

Abstract class.

Reads from and writes to binary files. Suitable for caching images.

Methods that must be implemented in concrete class:
key fetch_from_source
Optional:
cook

FileCache

Abstract class.

Reads from and writes to files with encoding.

Methods that must be implemented in concrete class:
key fetch_from_source
Optional:
cook encode decode

JsonFileCache

Abstract class.

This is just FileCache with JSON encoding and decoding.

fetch_from_source should return a JSON string. If OBJECT_PAIRS_HOOK is set, then decode will use that. Typically use: collections.OrderedDict to retain the order of elements.

Methods that must be implemented in concrete class:
key fetch_from_source
Optional:
cook OBJECT_PAIRS_HOOK

TwoLevelCache

Concrete class.

Generally this means an in-memory cache joined to a persistent cache (e.g, file, database). That means your cache persists over many executions, but doesn’t need to access the slower persistent cache more than once per item fetched.

To use it, implement the two caches and instantiate TwoLevelCache to join them. Pass in-memory cache class as the transient_cache and the persistent cache class as (surprise!) the pesistent_cache.

Release History

Release History

This version
History Node

1.0.15

History Node

1.0.14

History Node

1.0.13

History Node

1.0.12

History Node

1.0.11

History Node

1.0.10

History Node

1.0.9

History Node

1.0.8

History Node

1.0.6

History Node

1.0.5

History Node

1.0.4

History Node

1.0.3

History Node

1.0.2

History Node

1.0.1

History Node

1.0.0

Download Files

Download Files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

File Name & Checksum SHA256 Checksum Help Version File Type Upload Date
cachingutil-1.0.15-py2.py3-none-any.whl (16.6 kB) Copy SHA256 Checksum SHA256 py2.py3 Wheel Aug 18, 2017
cachingutil-1.0.15.tar.gz (11.2 kB) Copy SHA256 Checksum SHA256 Source Aug 18, 2017

Supported By

WebFaction WebFaction Technical Writing Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Heroku Heroku PaaS Kabu Creative Kabu Creative UX & Design Fastly Fastly CDN DigiCert DigiCert EV Certificate Rackspace Rackspace Cloud Servers DreamHost DreamHost Log Hosting