Skip to main content

collision-free cache folder

Project description

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'}

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

cfcf-0.0.8.tar.gz (3.1 kB view details)

Uploaded Source

Built Distribution

cfcf-0.0.8-py3-none-any.whl (3.9 kB view details)

Uploaded Python 3

File details

Details for the file cfcf-0.0.8.tar.gz.

File metadata

  • Download URL: cfcf-0.0.8.tar.gz
  • Upload date:
  • Size: 3.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.8.5

File hashes

Hashes for cfcf-0.0.8.tar.gz
Algorithm Hash digest
SHA256 f8bde0e7ebef7d5f6892f65c37e581f509027bd764c355499dbee656009c0f0c
MD5 07bab2c54aae68b7429072ddf6d6cbef
BLAKE2b-256 da371250a83b0a9543b582288d95ed99ff3e18b5d4fbb5216c4374ed7cc62eb3

See more details on using hashes here.

File details

Details for the file cfcf-0.0.8-py3-none-any.whl.

File metadata

  • Download URL: cfcf-0.0.8-py3-none-any.whl
  • Upload date:
  • Size: 3.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.8.5

File hashes

Hashes for cfcf-0.0.8-py3-none-any.whl
Algorithm Hash digest
SHA256 c7e0aa1cbdad019ce6479ffea289b5332550e74e80ffbd18e9b81bb8d360486c
MD5 004cfbfc7273175f9612fcbf92dfdcdc
BLAKE2b-256 db43384f504ce89d2775b3c33ff42a687881c6e8b181aaa8dc7975ce103bdf62

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