Skip to main content

cfcf

collision-free cache folder

This library creates a cache file for a remote resource or a file need additional processing. The cache will be duplicated, if an another process is creating the files. If the cache file already created, an interface will return the file path. This excluding concurrent writing feature makes to avoid the collision.

Installation

pip install cfcf

Usage

Following example running on '/tmp'

handle multiple files (directory mode)

import cfcf

def your_cache_getting_impl(arg1, arg2):
    print(arg1)
    import os
    print(os.getcwd())
    print(arg2)

print('#1# ', cfcf.get_dir('cache_name', your_cache_getting_impl, 'arg1', 'arg2'))
print('#2# ', cfcf.get_dir('cache_name', your_cache_getting_impl, 'arg1', 'arg2'))
arg1
/tmp/cache_name/01HGAJ22W2DZDCSC23V1A8RT20
arg2
#1#  /tmp/cache_name/01HGAJ22W2DZDCSC23V1A8RT20
#2#  /tmp/cache_name/01HGAJ22W2DZDCSC23V1A8RT20

handle a single file (file mode)

import cfcf

def your_cache_getting_impl(filename):
    import os
    print('Put a file in this dir. and return the path', os.getcwd())
    import pathlib
    path = pathlib.Path(filename)
    path.touch()
    return path

print('#1# ', cfcf.get_file('cache_name2', your_cache_getting_impl, 'filename.txt'))
print('#2# ', cfcf.get_file('cache_name2', your_cache_getting_impl, 'filename.txt'))
Put a file in this dir. and return the path /tmp/cache_name2/01HGAK6QQ516P2536QM38PFZ8M
#1#  /tmp/cache_name2/01HGAK6QQ516P2536QM38PFZ8M/cache_name2
#2#  /tmp/cache_name2/01HGAK6QQ516P2536QM38PFZ8M/cache_name2

handle a dict (object mode)

import cfcf

def your_cache_getting_impl(arg1, arg2):
    return {'arg1':arg1, 'arg2':arg2}

print('#1# ', cfcf.get_object('cache_name3', your_cache_getting_impl, 'arg1.1', 'arg2.1'))
print('#2# ', cfcf.get_object('cache_name3', your_cache_getting_impl, 'arg1.2', 'arg2.2'))
#1#  {'arg1': 'arg1.1', 'arg2': 'arg2.1'}
#2#  {'arg1': 'arg1.1', 'arg2': 'arg2.1'}

Release files for cfcf 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Built distribution (wheel)

Table of built distributions (wheels) for cfcf 0.1.0
File Interpreter ABI Platform
cfcf-0.1.0-py3-none-any.whl Python 3 none any Details

Release files / cfcf-0.1.0-py3-none-any.whl

Download URL cfcf-0.1.0-py3-none-any.whl
Size 4.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a0bf2d54c4125580d145255e18e0e42383fcaede77c0a192e91b220bf772ce47
BLAKE2b-256 checksum
How to use checksums
f4a0bb0e41317b0f08cdce36fe56e093c42d41afb9d32dda0e921a7237eb85d2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.8.5

Release history Release notifications | RSS feed

This release

0.1.0 This release

1 release file

0.0.9

2 release files

0.0.8

2 release files

0.0.7

2 release files

0.0.6

1 release file

0.0.5

1 release file

0.0.4

1 release file

0.0.3

1 release file

0.0.2

1 release file

0.0.1

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page