Skip to main content

Disk and file-based cache

Project description

Rationale: file-based cache in Django is essentially broken. Culling files is too costly. Large caches are forced to scan lots of files and do lots of deletes on some operations. Takes too long in the request/response cycle.

Solution: Each operation, “set” and “del” should delete at most two to ten expired keys.

Each “get” needs only check expiry and delete if needed. Make it speedy.

If only we had some kind of file-based database… we do! It’s called SQLite. For metadata and small stuff, use SQLite and for bigger things use files.

Features

  • Pure-Python

  • Developed on Python 2.7

  • Tested on CPython 2.7, 3.4, 3.5 and PyPy

  • Get full_path reference to value.

  • Allow storing raw data.

  • Small values stored in database.

  • Leverages SQLite native types: int, float, unicode, blob.

  • Thread-safe and process-safe.

  • Multiple eviction policies - Least-Recently-Stored - Least-Recently-Used - Least-Frequently-Used

  • Stampede barrier decorator.

  • Metadata support for “tag” to evict a group of keys at once.

Quickstart

Installing DiskCache is simple with pip:

$ pip install diskcache

You can access documentation in the interpreter with Python’s built-in help function:

>>> from diskcache import DjangoCache
>>> help(DjangoCache)

Caveats

  • Types matter in key equality comparisons. Comparisons like 1 == 1.0 and b'abc' == u'abc' return False.

Tutorial

TODO

Reference and Indices

License

Copyright 2016 Grant Jenks

Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Project details


Release history Release notifications | RSS feed

This version

1.1.0

Download files

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

Source Distribution

diskcache-1.1.0.tar.gz (128.6 kB view details)

Uploaded Source

Built Distribution

diskcache-1.1.0-py2.py3-none-any.whl (15.5 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file diskcache-1.1.0.tar.gz.

File metadata

  • Download URL: diskcache-1.1.0.tar.gz
  • Upload date:
  • Size: 128.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for diskcache-1.1.0.tar.gz
Algorithm Hash digest
SHA256 109309a1ef3170c2d872ccfb288f60651380e4ad66d4f37eec4e497c3c3fbec9
MD5 af80b55032a4c2c6ed155572ecbf04aa
BLAKE2b-256 d1f14c813940a8c89c6426c8636baeaf21ac6d936a555a56acd4e88407534ee2

See more details on using hashes here.

File details

Details for the file diskcache-1.1.0-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for diskcache-1.1.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 5be95fe5532cb531d643ceb436eada2c57bdbd79948924c9e047b9e9b6fb3f24
MD5 385eef636a94fda81b604e4488f3aa31
BLAKE2b-256 a334c219a7e85803c5eeaf2db254d253652897eb4620c510460c8bb9066a0a99

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page