Skip to main content

Write CACHEDIR.TAG files to mark directories containing cached content

Project description

CACHEDIR.TAG for Python

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

A CACHEDIR.TAG file indicate directories that contain cached data, e.g.

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

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

A directory (and all directories within it) can be flagged 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

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.1.tar.gz (3.3 kB view details)

Uploaded Source

Built Distribution

cachedir_tag-0.0.1-py2.py3-none-any.whl (3.1 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file cachedir-tag-0.0.1.tar.gz.

File metadata

  • Download URL: cachedir-tag-0.0.1.tar.gz
  • Upload date:
  • Size: 3.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.4.2 requests/2.25.1 setuptools/45.2.0 requests-toolbelt/0.8.0 tqdm/4.30.0 CPython/3.8.5

File hashes

Hashes for cachedir-tag-0.0.1.tar.gz
Algorithm Hash digest
SHA256 2ca17f6c73dd07784128c2ad369d4cdf672518f577d96bec0d946bde66626477
MD5 ed51528359fda02e1a5c9c37d8e45734
BLAKE2b-256 9d5af02c36424dceb7635b98b48d2179ffd3c7a886f7f2edfac0c30a18bb3b61

See more details on using hashes here.

File details

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

File metadata

  • Download URL: cachedir_tag-0.0.1-py2.py3-none-any.whl
  • Upload date:
  • Size: 3.1 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.4.2 requests/2.25.1 setuptools/45.2.0 requests-toolbelt/0.8.0 tqdm/4.30.0 CPython/3.8.5

File hashes

Hashes for cachedir_tag-0.0.1-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 0c446d31d7e0728a4ff8b2ca507b8ed1c0aa621cfd707715e07f5586c4f7a1cd
MD5 f9077edd3316bb17dd922f1f606f2954
BLAKE2b-256 5b1e6255baaa3e401d3449e0b0b4c04a6bef01e877c429313cc49853f425055d

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