X-Git-Url: https://wannabe.guru.org/gitweb/?a=blobdiff_plain;f=persistent.py;h=0ba931521a8841968068a6c7d97eb78edd86f78c;hb=07d89df04c5705cec39d6bdd10aea00bd5eb67e3;hp=ecf39c40be7e578f8d5d3b29835058074594416d;hpb=af108975dcae3fe59d1b7db6f7f8a3dd3c7c0045;p=python_utils.git diff --git a/persistent.py b/persistent.py index ecf39c4..0ba9315 100644 --- a/persistent.py +++ b/persistent.py @@ -31,7 +31,7 @@ class Persistent(ABC): def reuse_if_mtime_is_today() -> Callable[[datetime.datetime], bool]: """ A helper that returns a lambda appropriate for use in the - persistent_autoload_singleton decorator's may_reuse_persisted + persistent_autoloaded_singleton decorator's may_reuse_persisted parameter that allows persisted state to be reused as long as it was persisted on the same day as the load. @@ -49,7 +49,7 @@ def reuse_if_mtime_less_than_limit_sec( ) -> Callable[[datetime.datetime], bool]: """ A helper that returns a lambda appropriate for use in the - persistent_autoload_singleton decorator's may_reuse_persisted + persistent_autoloaded_singleton decorator's may_reuse_persisted parameter that allows persisted state to be reused as long as it was persisted within the past limit_seconds. @@ -58,6 +58,11 @@ def reuse_if_mtime_less_than_limit_sec( return lambda dt: (now - dt).total_seconds() <= limit_seconds +def dont_reuse_persisted_state_force_refresh( +) -> Callable[[datetime.datetime], bool]: + return lambda dt: False + + class PersistAtShutdown(enum.Enum): """ An enum to describe the conditions under which state is persisted @@ -69,7 +74,7 @@ class PersistAtShutdown(enum.Enum): ALWAYS = 2, -class persistent_autoload_singleton(Persistent): +class persistent_autoloaded_singleton(Persistent): """This class is meant to be used as a decorator around a class that: 1. Is a singleton; one global instance per python program. @@ -80,7 +85,7 @@ class persistent_autoload_singleton(Persistent): Here's and example usage pattern: - @persistent_autoload_singleton( + @persistent_autoloaded_singleton( filename = "my_cache_file.bin", may_reuse_persisted = reuse_if_mtime_less_than_limit_sec(60), persist_at_shutdown = PersistAtShutdown.IF_NOT_INITIALIZED_FROM_DISK,