arcache.cache module

This provides a handy image cache for PIL heavy TKInter work.

class arcache.cache.Cache(config_file: pathlib.Path = PosixPath('/home/docs/checkouts/readthedocs.org/user_builds/arcache/checkouts/latest/arcache/default.ini'), debug: bool = False)[source]

Bases: object

This provides the LRU cache logic.

cache_loaded = False
clear(persistent: bool = False)[source]

This allows us to clear the cache contents, if persistent is set to True the saved cache file will also be removed.

get()[source]

This fetches items from the cache.

keys() list[source]

Simulates a normal dictionary’s keys method.

load_cache_file()[source]

load the cache file.

load_image()[source]

This will load an image file into data and cleanup the file instance.

Take careful note of the image open, load, update, and close operations used here. If this process is improperly altered it will result in significant memory leakage.

log(*args, **kwargs)[source]

Really simple-ass logger.

put()[source]

This stores items into the cache.

refresh(resave: bool = False)[source]

Refreshes our cache contents.

param resave: If set to true this will force an update of the saved BIN file.

save_cache_file()[source]

In the event we are using a cached bin file, this will save / update it.

trim()[source]

resizes the cache to fit params.

update(kwargs: dict)[source]

Simulates a normal dictionary’s update method.

class arcache.cache.SlugCache(config_file: pathlib.Path = PosixPath('/home/docs/checkouts/readthedocs.org/user_builds/arcache/checkouts/latest/arcache/default.ini'), debug: bool = False)[source]

Bases: arcache.cache.Cache

This will allow us to store and update our images to reduce cpu overhead.

from_memory = False
provide(callback, *args, **kwargs) <module 'PIL.Image' from '/home/docs/checkouts/readthedocs.org/user_builds/arcache/envs/latest/lib/python3.9/site-packages/PIL/Image.py'>[source]
This will check to see if the callback output is already in the cache and if so return it,

Otherwise the callback will be executed, the results returned, and then cached.

save_image()[source]

This will either save the image to file or directly into cache.

arcache.cache.clean_args(args: list, kwargs: dict, exclusive: bool = False) dict[source]

Removes keys to prevent errors.

arcache.cache.config(config_file: pathlib.Path = PosixPath('/home/docs/checkouts/readthedocs.org/user_builds/arcache/checkouts/latest/arcache/default.ini'), section: str = 'cache') <module 'configparser' from '/home/docs/.asdf/installs/python/3.9.7/lib/python3.9/configparser.py'>[source]

This will grab our settings. TODO: We should move this into our larger config parser deal at a later time. :return: configparser

arcache.cache.get_args(args: list, kwargs: dict, clean: bool = False) list[source]

This will fetch arguments and jazz.

arcache.cache.get_name()[source]

This created a name based on passed arguments (handy for caching by config).

arcache.cache.prep_env(config_file: pathlib.Path = PosixPath('/home/docs/checkouts/readthedocs.org/user_builds/arcache/checkouts/latest/arcache/default.ini'), reload: bool = False) pathlib.Path[source]

This will get our filesystem setup for saving and transforming resources.

arcache.cache.slugify(value, allow_unicode=False)[source]

Taken from https://github.com/django/django/blob/master/django/utils/text.py Convert to ASCII if ‘allow_unicode’ is False. Convert spaces or repeated dashes to single dashes. Remove characters that aren’t alphanumerics, underscores, or hyphens. Convert to lowercase. Also strip leading and trailing whitespace, dashes, and underscores.