schrodinger.application.matsci.cache module

Module with functions related to caching.

Copyright Schrodinger, LLC. All rights reserved.

class schrodinger.application.matsci.cache.CacheInfo(hit, miss, maxsize, currsize)

Bases: tuple

currsize

Alias for field number 3

hit

Alias for field number 0

maxsize

Alias for field number 2

miss

Alias for field number 1

class schrodinger.application.matsci.cache.readonly_cached_property(func)

Bases: functools.cached_property

A cached property that cannot be set or deleted

class schrodinger.application.matsci.cache.frozenset_cached_property(func)

Bases: functools.cached_property

A cached property that automatically converts the property into a frozenset. Useful for ensuring that a set property is immutable.

schrodinger.application.matsci.cache.get_bound_cache(bound_func)

Gets the bound cache data associate with the bound method

Parameters

bound_func (function) – The bound function

Returns

Cache data associated with the bound method

Return type

BaseCacheData

class schrodinger.application.matsci.cache.BaseCacheData(maxsize=10000, *args, **kwargs)

Bases: collections.OrderedDict

Base limited size dictionary used for storing data

__init__(maxsize=10000, *args, **kwargs)

Constructs a new BaseCacheData

Parameters

maxsize (int) – The maxsize for the dictionary. The base class does not enforce the maxsize. The subclass needs to implement the size-limiting behavior.

property info

Get the cache data usage information

Return type

CacheInfo

Returns

Information for cache data usage

clear()

Clears the cache data

class schrodinger.application.matsci.cache.LRUCacheData(maxsize=10000, *args, **kwargs)

Bases: schrodinger.application.matsci.cache.BaseCacheData

Limited size dictionary where least-recently-accessed key in is removed first when the maxsize is reached

class schrodinger.application.matsci.cache.FIFOCacheData(maxsize=10000, *args, **kwargs)

Bases: schrodinger.application.matsci.cache.BaseCacheData

Limited size dictionary where first key in is removed first when the maxsize is reached

schrodinger.application.matsci.cache.memoized_method(cache_type=<class 'schrodinger.application.matsci.cache.FIFOCacheData'>, maxsize=10000)

Decorator for class methods that have weak reference to the self. This is a replacement for functools.lru_cache that works for class methods but not functions. Note like functools.lru_cache the values for the arguments of the method should be hashable.

Parameters
  • cache_type (BaseCacheData) – The cache data type

  • maxsize (int) – The maximum size of the cache