Skip to main content

cachinhgutil

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.

Metadata

Release files for cachingutil 1.2.7

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for cachingutil 1.2.7
File Size Uploaded
cachingutil-1.2.7.tar.gz 13.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for cachingutil 1.2.7
File Interpreter ABI Platform
cachingutil-1.2.7-py2.py3-none-any.whl Python 3, Python 2 none any Details

Total release size: 31.0 kB

Release files / cachingutil-1.2.7.tar.gz

Download URL cachingutil-1.2.7.tar.gz
Size 13.1 kB
Tags Source
SHA-256 checksum
How to use checksums
1f576f5b6972e2b40329f5f1a3ea15335ab695822b63f7a518d5ccbe7ee74029
BLAKE2b-256 checksum
How to use checksums
ce1a7e46e7df8c9deeb3a82b22908438ebd6036f694fa015da840564819b1130
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.12.1 pkginfo/1.4.2 requests/2.20.1 setuptools/40.4.3 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.6.7

Release files / cachingutil-1.2.7-py2.py3-none-any.whl

Download URL cachingutil-1.2.7-py2.py3-none-any.whl
Size 17.9 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
be144784779fefff9cda5856cd92e61197a0fc0b002778412d0e8e6d88985c24
BLAKE2b-256 checksum
How to use checksums
7542f3751a80da07358e8c895d8a6bbfd4a2adbf2900d8580c386c446debc61b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.12.1 pkginfo/1.4.2 requests/2.20.1 setuptools/40.4.3 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.6.7

Release history Release notifications | RSS feed

This release

1.2.7 This release

2 release files

1.2.6

2 release files

1.2.5

2 release files

1.2.0

2 release files

1.0.18

2 release files

1.0.17

2 release files

1.0.15

2 release files

1.0.14

2 release files

1.0.13

2 release files

1.0.11

2 release files

1.0.10

2 release files

1.0.9

2 release files

1.0.8

2 release files

1.0.6

2 release files

1.0.5

2 release files

1.0.4

2 release files

1.0.3

2 release files

1.0.2

2 release files

1.0.1

2 release files

1.0.0

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page