Skip to main content

Async Cache CDN client implementation

Project description

Cache CDN Client

A Python client library for interacting with the Cache CDN service based on CAFS, allowing efficient pushing and pulling of cached content.

Installation

pip install cafs-cache-cdn-client

Features

  • Asynchronous API for high-performance operations
  • Push local directories to cache
  • Pull cached content to local directories
  • Check existence of cached references
  • Tag references for easier access
  • Attach additional files to existing references
  • Delete references when no longer needed

Usage Example

import asyncio
import logging
from pathlib import Path
from cafs_cache_cdn_client import CacheCdnClient

# Configure logging to see detailed operation information
logging.basicConfig(level=logging.DEBUG)


async def main():
    # Initialize the client with the server URL
    # The connection_per_cafs_server parameter controls concurrency
    client = CacheCdnClient(
        'http://cache-server.example.com:8300',
        connection_per_cafs_server=10
    )

    # Use as an async context manager to ensure proper resource cleanup
    async with client:
        # Push a local directory to cache with a 2-hour TTL
        await client.push('project_name', 'build_artifacts',
                          '/path/to/build/output', ttl_hours=2,
                          comment='Build artifacts from CI run #123')

        # Check if a reference exists
        exists = await client.check('project_name', 'build_artifacts')
        print(f"Reference exists: {exists}")

        # Pull cached content to a local directory
        await client.pull('project_name', 'build_artifacts',
                          '/path/to/destination')

        # Tag a reference for easier access later
        await client.tag('project_name', 'build_artifacts', 'latest_stable')

        # Attach an additional file to an existing reference
        await client.attach('project_name', 'build_artifacts',
                            Path('/path/to/metadata.json'))

        # Delete a reference when no longer needed
        await client.delete('project_name', 'old_artifacts')


# Run the example
if __name__ == '__main__':
    asyncio.run(main())

API Reference

CacheCdnClient

  • Constructor: CacheCdnClient(server: str, connection_per_cafs_server: int = 1)

    • server: URL of the cache server
    • connection_per_cafs_server: Number of concurrent connections per CAFS server
  • Methods:

    • push(repo: str, ref: str, directory: Path | str, ttl_hours: int = 0, comment: str | None = None) - Push a local directory to cache
    • pull(repo: str, ref: str, directory: Path | str) - Pull cached content to a local directory
    • check(repo: str, ref: str) -> bool - Check if a reference exists
    • tag(repo: str, ref: str, tag: str) - Create a tag for a reference
    • attach(repo: str, ref: str, file_path: Path) - Attach a file to an existing reference
    • delete(repo: str, ref: str) - Delete a reference

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

cafs_cache_cdn_client-1.0.6.tar.gz (12.6 kB view details)

Uploaded Source

Built Distribution

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

cafs_cache_cdn_client-1.0.6-py3-none-any.whl (16.5 kB view details)

Uploaded Python 3

File details

Details for the file cafs_cache_cdn_client-1.0.6.tar.gz.

File metadata

  • Download URL: cafs_cache_cdn_client-1.0.6.tar.gz
  • Upload date:
  • Size: 12.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.2 CPython/3.13.2 Darwin/23.4.0

File hashes

Hashes for cafs_cache_cdn_client-1.0.6.tar.gz
Algorithm Hash digest
SHA256 088e78ef43b510d56135d511a8f4dc6191181300307b611cb85a56e4414ba313
MD5 9f7a83cb4950a8720950c70a823b6dfd
BLAKE2b-256 4d92af2ac3841538b4612003c65baa7190e7692a5d1355b924ba3d417cc3dd58

See more details on using hashes here.

File details

Details for the file cafs_cache_cdn_client-1.0.6-py3-none-any.whl.

File metadata

File hashes

Hashes for cafs_cache_cdn_client-1.0.6-py3-none-any.whl
Algorithm Hash digest
SHA256 b46744244ebbb4408199f63a75be833dddbc8587622bebd334b6505b2127e649
MD5 f1f68e6aea822cb7211a74728d0d2bc1
BLAKE2b-256 9e2051b642b2dbb53d6c2a69abd98d890c8e73084af4ee4adf8be6ed1cb9955f

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