Skip to main content

A package for caching downloads of specially formatted files.

Project description

USTDownloadCache

GitHub license GitHub tag (latest by date) GitHub last commit

About

The USTDownloadCache is used by the Ubuntu Security Team to improve the runtime of other packages by caching certain JSON files.

Using USTDownloadCache

Example:

import logging
from ust_download_cache import USTDownloadCache

logger = logging.getLogger("")
download_cache = USTDownloadCache(logger)

url = "URL_GOES_HERE"
data = download_cache.get_data_from_url(url)
metadata = download_cache.get_cache_metadata_from_url(url) # used by USTDownloadCache

Metadata

The USTDownloadCache relies on metadata contained within the file it is downloading/caching. The JSON must supply a "metadata" key, which provides a timestamp (seconds since the Unix epoch) and time to live (ttl) in seconds. The cached version of the file is considered to be expired when timestamp + ttl > now

{
    "metadata": {
        "timestamp": 1591887905,
        "ttl": 3600,
        "version": "1.0"
    },
    "data": {
        "name1": "value1",
        "name2": "value2"
    }
}

Installation

From Source

To install from source, you can clone this repository and install USTDownloadCache:

$> git clone https://github.com/canonical/ust-download-cache
$> pip3 install --user ./ust-download-cache/

As a dependency

As USTDownloadCache is not in PyPI at the moment, you must use the github tarball in your setup.py:

install_requires = [
        "ust-download-cache @ https://github.com/canonical/ust-download-cache/archive/v1.0.1.tar.gz",
]

Development

Installing precommit hooks

To install the precommit hooks, run

pip3 install --user pre-commit
~/.local/bin/pre-commit install

Running the test suite

You can run the automated test suite by running

$> python3 -m pytest

An HTML code coverage report will be generated at ./htmlcov. You can view this with any web browser (e.g. firefox ./htmlcov/index.html).

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

UST Download Cache-2.0.0.tar.gz (4.7 kB view details)

Uploaded Source

Built Distribution

UST_Download_Cache-2.0.0-py3-none-any.whl (17.5 kB view details)

Uploaded Python 3

File details

Details for the file UST Download Cache-2.0.0.tar.gz.

File metadata

  • Download URL: UST Download Cache-2.0.0.tar.gz
  • Upload date:
  • Size: 4.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/45.2.0 requests-toolbelt/0.9.1 tqdm/4.47.0 CPython/3.8.2

File hashes

Hashes for UST Download Cache-2.0.0.tar.gz
Algorithm Hash digest
SHA256 10e3abf7a805e19947f06f9beb08f8d01cab49dbc9a397407df5388c4fa9410e
MD5 f46af25ca499e7ae91a8f27602904c27
BLAKE2b-256 14fa8bbbe1346980593a0f20b451e78583af3b5050e48fa01cd467fe25cab38a

See more details on using hashes here.

File details

Details for the file UST_Download_Cache-2.0.0-py3-none-any.whl.

File metadata

  • Download URL: UST_Download_Cache-2.0.0-py3-none-any.whl
  • Upload date:
  • Size: 17.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/45.2.0 requests-toolbelt/0.9.1 tqdm/4.47.0 CPython/3.8.2

File hashes

Hashes for UST_Download_Cache-2.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 abcf0272fb6fc6289ca0b7546af6cb4d49a288e798c30ee0c0919b7cafcd865f
MD5 060e8136e9944fde38793d887fa05112
BLAKE2b-256 f903b65f67c0b83f6a378c95aaeb421c0dbd1caf1ed23e7df312c5d7caaa0caa

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