Cachify Context
The cachify context provides a simple interface for managing caching operations. Generally speaking, unless you need to customize your cachify context, a single instance of the cachify context is sufficient for most use cases.
API Reference
Bases: abc.ABC
The CacheContext is used to manage the cache context
Initializes the CacheContext
METHOD | DESCRIPTION |
---|---|
add_function |
Adds a function to the cachify context |
bind_session |
Binds the session |
configure_classes |
Configures the classes |
create_cachify |
Creates a cachify object |
register |
Registers a function to cachify |
register_object |
Register the underlying object |
register_object_method |
Registers an object method function to be cached |
safely |
Safely wraps the function |
ATTRIBUTE | DESCRIPTION |
---|---|
ctx |
Returns the KV Session if it is available
TYPE:
|
has_async_loop |
Checks if the current process is running in an async loop
TYPE:
|
session |
Returns the session
TYPE:
|
Source code in kvdb/io/cachify/cache.py
has_async_loop
property
Checks if the current process is running in an async loop
add_function
add_function(
function: typing.Union[typing.Callable, str],
function_name: typing.Optional[str] = None,
**kwargs
) -> kvdb.io.cachify.base.Cachify
Adds a function to the cachify context
Source code in kvdb/io/cachify/cache.py
bind_session
configure_classes
configure_classes(
cachify_class: typing.Optional[
typing.Type["Cachify"]
] = None,
is_init: typing.Optional[bool] = False,
)
Configures the classes
Source code in kvdb/io/cachify/cache.py
create_cachify
Creates a cachify object
Source code in kvdb/io/cachify/cache.py
register
register(
function: typing.Callable[
kvdb.io.cachify.base.FuncP,
kvdb.io.cachify.base.FuncT,
],
**kwargs
) -> typing.Union[
typing.Awaitable[kvdb.io.cachify.base.FuncT],
kvdb.io.cachify.base.FuncT,
]
register(
function: typing.Callable[
kvdb.io.cachify.base.FuncP,
kvdb.io.cachify.base.FuncT,
],
**kwargs
) -> typing.Callable[
kvdb.io.cachify.base.FuncP,
typing.Union[
typing.Awaitable[kvdb.io.cachify.base.FuncT],
kvdb.io.cachify.base.FuncT,
],
]
register(
function: typing.Optional[
typing.Union[
kvdb.io.cachify.base.FunctionT,
typing.Callable[
kvdb.io.cachify.base.FuncP,
kvdb.io.cachify.base.FuncT,
],
]
] = None,
ttl: typing.Optional[int] = 60 * 10,
ttl_kws: typing.Optional[typing.List[str]] = [
"cache_ttl"
],
keybuilder: typing.Optional[typing.Callable] = None,
name: typing.Optional[
typing.Union[str, typing.Callable]
] = None,
typed: typing.Optional[bool] = True,
exclude_keys: typing.Optional[typing.List[str]] = None,
exclude_null: typing.Optional[bool] = True,
exclude_exceptions: typing.Optional[
typing.Union[bool, typing.List[Exception]]
] = True,
exclude_if: typing.Optional[typing.Callable] = None,
prefix: typing.Optional[str] = "_kvc_",
exclude_null_values_in_hash: typing.Optional[
bool
] = None,
exclude_default_values_in_hash: typing.Optional[
bool
] = None,
disabled: typing.Optional[
typing.Union[bool, typing.Callable]
] = None,
disabled_kws: typing.Optional[typing.List[str]] = [
"cache_disable"
],
invalidate_after: typing.Optional[
typing.Union[int, typing.Callable]
] = None,
invalidate_if: typing.Optional[typing.Callable] = None,
invalidate_kws: typing.Optional[typing.List[str]] = [
"cache_invalidate"
],
overwrite_if: typing.Optional[typing.Callable] = None,
overwrite_kws: typing.Optional[typing.List[str]] = [
"cache_overwrite"
],
retry_enabled: typing.Optional[bool] = False,
retry_max_attempts: typing.Optional[int] = 3,
retry_giveup_callable: typing.Optional[
typing.Callable[..., bool]
] = None,
timeout: typing.Optional[float] = 5.0,
verbosity: typing.Optional[int] = None,
raise_exceptions: typing.Optional[bool] = True,
encoder: typing.Optional[
typing.Union[str, typing.Callable]
] = None,
decoder: typing.Optional[
typing.Union[str, typing.Callable]
] = None,
hit_setter: typing.Optional[typing.Callable] = None,
hit_getter: typing.Optional[typing.Callable] = None,
cache_max_size: typing.Optional[int] = None,
cache_max_size_policy: typing.Optional[
typing.Union[str, kvdb.types.common.CachePolicy]
] = kvdb.types.common.CachePolicy.LFU,
post_init_hook: typing.Optional[
typing.Union[str, typing.Callable]
] = None,
post_call_hook: typing.Optional[
typing.Union[str, typing.Callable]
] = None,
hset_enabled: typing.Optional[bool] = True,
silenced_stages: typing.Optional[
typing.List[str]
] = None,
) -> typing.Callable[
kvdb.io.cachify.base.FuncP,
typing.Union[
typing.Awaitable[kvdb.io.cachify.base.FuncT],
kvdb.io.cachify.base.FuncT,
],
]
register(
function: typing.Optional[
kvdb.io.cachify.base.FunctionT
] = None,
**kwargs
) -> typing.Callable[
[kvdb.io.cachify.base.FunctionT],
kvdb.io.cachify.base.FunctionT,
]
Registers a function to cachify
Source code in kvdb/io/cachify/cache.py
register_object
register_object(
validator_function_name: typing.Optional[str] = None,
debug_enabled: typing.Optional[bool] = None,
**_kwargs
) -> types.ModuleType
Register the underlying object
Source code in kvdb/io/cachify/cache.py
241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 |
|
register_object_method
register_object_method(
**kwargs,
) -> typing.Callable[
[kvdb.io.cachify.base.FunctionT],
kvdb.io.cachify.base.FunctionT,
]
Registers an object method function to be cached
Source code in kvdb/io/cachify/cache.py
safely
Safely wraps the function