Skip to main content

Handle CACHEDIR.TAG files, indicating directories that contain cached content

Project description

CACHEDIR.TAG for Python

This library handles CACHEDIR.TAG files. Allowing any arbitrary directory to be marked as a cache directory.

A CACHEDIR.TAG file indicates a directory that contain cached data, e.g.

  • downloads
  • previews, and thumbnails
  • build artefacts, and other intermediate results

Cached data is useful, but not essential - if necessary it can be regenerated, or downloaded again. However backup programs, disk cleanup utilities, & other software can't know if an arbitrary path is cached data, unless it is marked.

A directory (and all directories within it) can be marked as a cache by writing a regular file named CACHEDIR.TAG, with the first 43 bytes being

Signature: 8a477f597d28d172789f06886806bc55

After this signature any other text can be included. The specification suggests lines of text beginning with #, encoded as UTF-8. E.g.

# This file is a cache directory tag created by (application name).
# For information about cache directory tags, see:
#	http://www.brynosaurus.com/cachedir/

This library follows that suggestion.

Installation

$ python -m pip install cachedir-tag

Usage

Create your cache directory, if necessary

>>> import os, cachedir_tag
>>> os.mkdir('/var/cache/yourapp')

Tag it, this creates a new CACHEDIR.TAG file

>>> cachedir_tag.tag('/var/cache/yourapp')

Check whether the directory is tagged

>>> cachedir_tag.is_tagged('/var/cache/yourapp')
True

Check whether a sub-directory (which may not exist yet) is tagged

>>> cachedir_tag.is_tagged('/var/cache/yourapp/somedir')
True

License

MIT

Alternatives

Operating systems and similar platforms usually have conventions about where to place cached data. A CACHEDIR.TAG file isn't needed if you follow these conventions, but it doesn't hurt either.

More information

Project details


Download files

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

Source Distribution

cachedir_tag-0.0.5.tar.gz (4.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

cachedir_tag-0.0.5-py2.py3-none-any.whl (4.0 kB view details)

Uploaded Python 2Python 3

File details

Details for the file cachedir_tag-0.0.5.tar.gz.

File metadata

  • Download URL: cachedir_tag-0.0.5.tar.gz
  • Upload date:
  • Size: 4.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.14

File hashes

Hashes for cachedir_tag-0.0.5.tar.gz
Algorithm Hash digest
SHA256 40ea1bffff8de77de7e094f70624805b2a6c5b989982094a5db4e684763a86e1
MD5 c4393e120ed633152b64d315143d62f2
BLAKE2b-256 c4cca4836b21108573851b701a3137b16eebfd589e5bdff569f5f5173af36bfe

See more details on using hashes here.

File details

Details for the file cachedir_tag-0.0.5-py2.py3-none-any.whl.

File metadata

  • Download URL: cachedir_tag-0.0.5-py2.py3-none-any.whl
  • Upload date:
  • Size: 4.0 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.14

File hashes

Hashes for cachedir_tag-0.0.5-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 18af8e157251ab916277978f4337070820aced9503ce3a59171a1c296facc0fc
MD5 fec5972c07f880450f7acbcd5c78d48c
BLAKE2b-256 baccb994cf19817f738739de6a9a0574370a1d5cd192c025fc5f5afa5c68b5d3

See more details on using hashes here.

Supported by

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