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 Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

cfcf-0.1.0-py3-none-any.whl (4.1 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: cfcf-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 4.1 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.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 a0bf2d54c4125580d145255e18e0e42383fcaede77c0a192e91b220bf772ce47
MD5 e724dceb00b07ebeaa914465e076df87
BLAKE2b-256 f4a0bb0e41317b0f08cdce36fe56e093c42d41afb9d32dda0e921a7237eb85d2

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