Skip to main content

Python package for monolithcaching

Project description

Monolith Caching

Using License Apache 2.0

This module manages caching for directories. Using this package you are able to create tempory directories, access meta data around the directory, and cache in AWS S3. The tempory directories are wiped once the program crashes or finishes unless the cache is locked. Caches can also be managed across threads by configuring a Redis port.

Usage

Caches are managed by a CacheManager which can be initialized by the following code:

from monolithcaching import CacheManager

manager = CacheManager(local_cache_path="/path/to/local/directory/for/all/caches")
manager.create_cache()

This creates a local cache. If we wanted to point to an existing cache we would have set the existing_cache parameter to the path of the cache with the following code:

manager.create_cache(existing_cache="/path/to/existing/cache")

cache_path = manager.cache_path

Connecting to S3 AWS

Connecting to S3 for caching can be done by the following code:

manager = CacheManager(s3_cache_path="/path/to/local/directory/for/all/caches", s3=True)

Connecting to Redis

Connecting to Redis enables the cache manager to keep track of all caches and the amount of open cache processes pointing to each cache. This enables us to do safe caching over multiple threads, processes, or servers (if you are caching in S3). If the cache is not locked, then when the count turns to zero, the cache is wiped. We can connect to Redis by configuring the port and host parameters as seen in the following code:

manager = CacheManager(local_cache_path="/path/to/local/directory/for/all/caches", port=6379, 
                       host="localhost")

Locking Cache

We can lock the cache, this is where the cache remains even if the program finishes or crashes. This can be done by the following code:

manager.lock_cache()
manager.unlock_cache()

Meta Data

You can access meta data about the cache in the form of a dict with the following command:

meta = manager.meta 

This contains the datetime of when the cache was made, and the ID of the cache. You can add meta data to the meta via the following command:

manager.insert_meta(key="some key", value="some value")
pip install git+ssh://git@github.com/MonolithAILtd/caching.git@master#egg=caching
pip install git+https://github.com/MonolithAILtd/caching#egg=caching

Contributing

This repo is still fairly new so contributing will require some communication as we are currently working on supporting thread safe caching locally without the need for Redis. You can contact with ideas and outline for a feature at maxwell@monolithai.com.

Writing code is not the only way you can contribute. Merely using the module is a help, if you come across any issues feel free to raise them in the issues section of the Github page as this enables us to make the module more stable. If there are any issues that you want to solve, your pull request has to have documentation, 100% unit test coverage and functional testing.

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

monolithcaching-0.0.9.tar.gz (9.5 kB view details)

Uploaded Source

File details

Details for the file monolithcaching-0.0.9.tar.gz.

File metadata

  • Download URL: monolithcaching-0.0.9.tar.gz
  • Upload date:
  • Size: 9.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.3.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.0 CPython/3.8.5

File hashes

Hashes for monolithcaching-0.0.9.tar.gz
Algorithm Hash digest
SHA256 623d52b69a8fda137e15b0eb54148febc7b424bb7d6bf7dcb907c496b4a6dab9
MD5 f40d70d03d3e024595642b953754a713
BLAKE2b-256 d3560bb43a31890a3a423a1e63fffeb2e799f577baf038a1c0c1ec7a282ac014

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