Skip to main content

my Sweet Cache

This project let make fast and simply cache

autors

Bartłomiej Chwiłkowski (github: chwilko)

Structure

mySweetCache: mySweetCache.py: main functions utils.py: other function usefull to

Functions

cache

def cache(
    MSC_name: Optional[str] = None,
    *,
    header: Optional[str] = None,
    sep_in_data: str = "",
) -> Callable:

Wrapper add possibility caching function result to wrapped function

If file MSC_name exist in _CACHE_FILES wraped function return cache from right cache. else make new cache Wrapper add optional argument 'use_cache'. If use_cache == False cache will overwrite.

Args: MSC_name (Optional[str], optional): cache key. Defaults to None. header (Optional[str], optional): data description. Defaults to None. sep_in_data (str, optional): Separator between array items for text output. If "" (empty), a binary file is written, equivalent to file.write(a.tobytes()). Defaults to "".

Returns: callable: Function with cache functionality.

read_cache

def read_cache(MSC_name: str) -> Any:

Function to fast read MSC.

Args: MSC_name (str): cache key to read.

Raises: NameError: If this cache don't exist.

Returns: np.array: Previously saved data.

save_cache

save_cache(
    MSC_name: str,
    data: ndarray,
    *,
    header: Optional[str] = None,
    sep_in_data: str = "",
)

Function to fast save MSC.

Args: MSC_name (str): cache key to save. data (ndarray): data to save sep_in_data (Optional[str], optional): Separator between array items for text output. If "" (empty), a binary file is written, equivalent to file.write(a.tobytes()).

use_par

Decorator set self argument as first function argument.

def use_par(par):

use_pars

Decorator set self arguments as first function arguments.

def use_pars(*pars):

How to use

example use:
  @cache("key")
  def long_working_function() -> np.ndarray:
      # long code to work
      return ...

example use 2:
  @cache("key")
  @use_parms(11, 21)
  def long_working_function(arg1, arg2) -> np.ndarray:
      # long code to work
      return ...

After first call this function result is saved in .MScache_files/key In next call instead recount value will be read from cache. To recount call long_counting_function(use_cache=False) then cache will be overwrited or delete .MScache_files/try file.

WARNING! If you define two function with the same key, there two functions will share the same cache file.

Licence

MIT

Release files for mySweetCache 1.1.0

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

Source distribution (sdist)

Source distribution for mySweetCache 1.1.0
File Size Uploaded
mysweetcache-1.1.0.tar.gz 36.7 kB Details

Built distribution (wheel)

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

Total release size: 44.1 kB

Release files / mysweetcache-1.1.0.tar.gz

Download URL mysweetcache-1.1.0.tar.gz
Size 36.7 kB
Tags Source
SHA-256 checksum
How to use checksums
7cf74644e06bf03791d5b1125f3d36fbfc3873d87a1e1e5fceed78b11a3b5f26
BLAKE2b-256 checksum
How to use checksums
ebe9f4ea9826c72a17a522b2f8098569f3f688d4c90ed317358ec10893fd2c9c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.8.10

Release files / mysweetcache-1.1.0-py3-none-any.whl

Download URL mysweetcache-1.1.0-py3-none-any.whl
Size 7.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
5923cc443de1249d80bf095d7cc50d0cf208ad8c0978fe1d1432450df7be6b4a
BLAKE2b-256 checksum
How to use checksums
8df5bc5fb04e5230658a6941be0ea40ea1b2fcb6c525475ba5561f95546bf453
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.8.10

Release history Release notifications | RSS feed

This release

1.1.0 This release

2 release files

1.0.0

2 release files

0.1.0

2 release files

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