DiskCache Development

DiskCache is developed in the GitHub repository of the diskcache-community fork. Questions and ideas go to Discussions, bugs to the issue tracker.

Collaborators Welcome

  1. Search issues or open a new issue to start a discussion around a bug.

  2. Fork the GitHub repository and make your changes in a new branch.

  3. Write a test which shows the bug was fixed.

  4. Send a pull request. It merges once CI is green and it has been reviewed.

Requests for Contributions

  1. Command-line interface. Operations to support: get, set, store, delete, expire, evict, clear, path, check, stats.

  2. Django admin interface for cache stats and interaction.

  3. Cache stampede barrier (source prototype in repo).

  4. API Compatibility

    1. Shelf interface

    2. DBM interface

  5. Backend Compatibility

    1. Flask-Caching

    2. Beaker

    3. dogpile.cache

Get the Code

DiskCache is actively developed in a GitHub repository.

You can either clone the public repository:

$ git clone https://github.com/secondwindoss/diskcache-community.git

Download the tarball:

$ curl -OL https://github.com/secondwindoss/diskcache-community/tarball/master

Or, download the zipball:

$ curl -OL https://github.com/secondwindoss/diskcache-community/zipball/master

Installing Dependencies

Install development dependencies with pip:

$ pip install -r requirements-dev.txt

All packages for running tests and the lint checks will be installed.

Additional packages like pylibmc and redis along with their server counterparts are necessary for the benchmarks.

Testing

DiskCache tests against five versions of Python:

  • CPython 3.10

  • CPython 3.11

  • CPython 3.12

  • CPython 3.13

  • CPython 3.14

Testing uses tox. If you don’t want to install all the development requirements, then, after downloading, you can simply run:

$ tox

tox -e py runs the test suite with pytest in the current interpreter. The options in the [pytest] section of tox.ini run the tests in parallel, collect the doctests from the .rst files and fail the run if branch coverage of the diskcache package drops below 98%. The lint checks are tox environments as well:

$ tox -e bluecheck,isortcheck,flake8,mypy,pylint,doc8,docs

Read the Docs builds the docs directory from master on every push, configured by .readthedocs.yaml with the build dependencies in docs/requirements.txt.

Stress tests can be run independently as a module. They are kept in the tests directory and prefixed with stress_test_. Stress tests accept many arguments. Read the help for details.

$ python -m tests.stress_test_core --help
usage: stress_test_core.py [-h] [-n OPERATIONS] [-g GET_AVERAGE]
                           [-k KEY_COUNT] [-d DEL_CHANCE] [-w WARMUP]
                           [-e EXPIRE] [-t THREADS] [-p PROCESSES] [-s SEED]
                           [--no-create] [--no-delete] [-v EVICTION_POLICY]

optional arguments:
  -h, --help            show this help message and exit
  -n OPERATIONS, --operations OPERATIONS
                        Number of operations to perform (default: 10000)
  -g GET_AVERAGE, --get-average GET_AVERAGE
                        Expected value of exponential variate used for GET
                        count (default: 100)
  -k KEY_COUNT, --key-count KEY_COUNT
                        Number of unique keys (default: 10)
  -d DEL_CHANCE, --del-chance DEL_CHANCE
                        Likelihood of a key deletion (default: 0.1)
  -w WARMUP, --warmup WARMUP
                        Number of warmup operations before timings (default:
                        10)
  -e EXPIRE, --expire EXPIRE
                        Number of seconds before key expires (default: None)
  -t THREADS, --threads THREADS
                        Number of threads to start in each process (default:
                        1)
  -p PROCESSES, --processes PROCESSES
                        Number of processes to start (default: 1)
  -s SEED, --seed SEED  Random seed (default: 0)
  --no-create           Do not create operations data (default: True)
  --no-delete           Do not delete operations data (default: True)
  -v EVICTION_POLICY, --eviction-policy EVICTION_POLICY

If stress exits normally then it worked successfully. Some stress is run by the test suite but the iteration count is limited. More rigorous testing requires increasing the iteration count to millions. At that level, it’s best to just let it run overnight. Stress testing will stop at the first failure.

Running Benchmarks

The DiskCache Benchmarks page is written by the scripts in tests/benchmarks. driver.py starts memcached and Redis, runs each store in its own process from a virtual environment with diskcache-community and one with diskcache 5.6.3, and stores JSON results; report.py turns the results into the page and its charts. The page’s last section lists the commands.

The scripts below produced the old benchmarks (2019). Running and plotting them is a two step process. Each is a Python script in the tests directory. Benchmark scripts are prefixed with benchmark_. For example:

$ python tests/benchmark_core.py --help
usage: benchmark_core.py [-h] [-p PROCESSES] [-n OPERATIONS] [-r RANGE]
                         [-w WARMUP]

optional arguments:
  -h, --help            show this help message and exit
  -p PROCESSES, --processes PROCESSES
                        Number of processes to start (default: 8)
  -n OPERATIONS, --operations OPERATIONS
                        Number of operations to perform (default: 100000)
  -r RANGE, --range RANGE
                        Range of keys (default: 100)
  -w WARMUP, --warmup WARMUP
                        Number of warmup operations before timings (default:
                        1000)

Benchmark output is stored in text files prefixed with timings_ in the tests directory. Plotting the benchmarks is done by passing the timings file as an argument to plot.py.