Skip to main content

Package to fast and easy cache

Project description

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

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

mysweetcache-1.0.0.tar.gz (36.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mysweetcache-1.0.0-py3-none-any.whl (7.3 kB view details)

Uploaded Python 3

File details

Details for the file mysweetcache-1.0.0.tar.gz.

File metadata

  • Download URL: mysweetcache-1.0.0.tar.gz
  • Upload date:
  • Size: 36.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.8.10

File hashes

Hashes for mysweetcache-1.0.0.tar.gz
Algorithm Hash digest
SHA256 4f951e611462f07de21c159b2b9f7cf6d02b480d19f1c4d76d29d1c8a04327ea
MD5 32ecd21998e2501e7d9be7a4701113af
BLAKE2b-256 606465a2599b6901fca4d92fa29e56e1e5f9b9e2b5ec2d69ae3a3aa0d811f804

See more details on using hashes here.

File details

Details for the file mysweetcache-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: mysweetcache-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 7.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.8.10

File hashes

Hashes for mysweetcache-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f6f52a7a0a29a93ac8295cc2ca97af28924169666eca36d327e8f51cc00a2211
MD5 8cfdc843606ad60cbbbd1efeb74a59df
BLAKE2b-256 c74b4a469f2504a41fef8027c1b3cdbf1762a0775ba1d23040646df0f40a18b5

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