Cachify Object
The cachify object is the wrapper around each individual cached function that is managed by the cachify context.
The following example demonstrates usage of the Cachify
class to cache objects.
objects.py"""
A Very basic demonstration of how to use cachify with objects
Without any arguments, cachify will use the default settings and initialize
a default session.
Similiar to registering functions, you can register an object for caching.
- The objects functions that are explicitly registered will be cached, and any that are not
will not be affected.
Run this example:
# cwd: examples/caching
$ python objects.py
"""
import time
import abc
import asyncio
from lazyops.utils.times import Timer
from kvdb.io import cachify
from kvdb.utils.logs import logger
DEBUG_ENABLED = False
@cachify.register_object()
class TestObject(abc.ABC):
def __init__(self, *args, **kwargs):
logger.info('running init')
@cachify.register(ttl = 10, verbosity = 2 if DEBUG_ENABLED else None, cache_max_size = 15)
async def async_fibonacci(self, number: int):
if number == 0: return 0
elif number == 1: return 1
return await self.async_fibonacci(number - 1) + await self.async_fibonacci(number - 2)
@cachify.register(ttl = 10, verbosity = 2 if DEBUG_ENABLED else None)
def fibonacci(self, number: int):
if number == 0: return 0
elif number == 1: return 1
return self.fibonacci(number - 1) + self.fibonacci(number - 2)
# No Cache Versions
async def async_fibonacci_nc(self, number: int):
if number == 0: return 0
elif number == 1: return 1
return await self.async_fibonacci_nc(number - 1) + await self.async_fibonacci_nc(number - 2)
def fibonacci_nc(self, number: int):
if number == 0: return 0
elif number == 1: return 1
return self.fibonacci_nc(number - 1) + self.fibonacci_nc(number - 2)
async def run_tests(
start_n: int = 1,
runs: int = 10,
print_every: int = 5,
):
"""
Test that both results are the same.
"""
t = Timer(format_ms=True)
o = TestObject()
# Test Sync
st = Timer(format_ms=True)
for i in range(runs):
r = o.fibonacci(start_n+i)
d = st.duration_s
if i % print_every == 0:
logger.info(f'[Sync - {i}/{runs}] Result: {r} | Time: {d}')
logger.info(f'[Sync] Cache Average Time: {st.total_average_s(runs)} | Total Time: {st.total_s}')
logger.info(o.fibonacci.cache_info(), prefix = '[Sync] Cache Info')
# Test Async
at = Timer(format_ms=True)
for i in range(runs):
r = await o.async_fibonacci(start_n+i)
d = at.duration_s
if i % print_every == 0:
logger.info(f'[Async - {i}/{runs}] Result: {r} | Time: {d}')
logger.info(f'[Async] Cache Average Time: {at.total_average_s(runs)} | Total Time: {at.total_s}')
logger.info(await o.async_fibonacci.cache_info(), prefix = '[Async] Cache Info')
logger.info(t.total_s, prefix = 'Total Time')
# Clear the Cache
o.fibonacci.clear()
logger.info(o.fibonacci.cache_info(), prefix = '[Sync] Cache Info')
await o.async_fibonacci.clear()
logger.info(await o.async_fibonacci.cache_info(), prefix = '[Async] Cache Info')
logger.info('Testing Non-Cached Functions')
t = Timer(format_ms=True)
# Test Sync
st = Timer(format_ms=True)
for i in range(runs):
r = o.fibonacci_nc(start_n+i)
d = st.duration_s
if i % print_every == 0:
logger.info(f'[Sync - {i}/{runs}] Result: {r} | Time: {d}')
logger.info(f'[Sync] Cache Average Time: {st.total_average_s(runs)} | Total Time: {st.total_s}')
# Test Async
at = Timer(format_ms=True)
for i in range(runs):
r = await o.async_fibonacci_nc(start_n+i)
d = at.duration_s
if i % print_every == 0:
logger.info(f'[Async - {i}/{runs}] Result: {r} | Time: {d}')
logger.info(f'[Async] Cache Average Time: {at.total_average_s(runs)} | Total Time: {at.total_s}')
logger.info(t.total_s, prefix = 'Total Time')
if __name__ == '__main__':
asyncio.run(run_tests(
start_n = 5,
runs = 40,
print_every = 5,
))
"""
A Very basic demonstration of how to use cachify with objects
Without any arguments, cachify will use the default settings and initialize
a default session.
Similiar to registering functions, you can register an object for caching.
- The objects functions that are explicitly registered will be cached, and any that are not
will not be affected.
Run this example:
# cwd: examples/caching
$ python objects.py
"""
import time
import abc
import asyncio
from lazyops.utils.times import Timer
from kvdb.io import cachify
from kvdb.utils.logs import logger
DEBUG_ENABLED = False
@cachify.register_object()
class TestObject(abc.ABC):
def __init__(self, *args, **kwargs):
logger.info('running init')
@cachify.register(ttl = 10, verbosity = 2 if DEBUG_ENABLED else None, cache_max_size = 15)
async def async_fibonacci(self, number: int):
if number == 0: return 0
elif number == 1: return 1
return await self.async_fibonacci(number - 1) + await self.async_fibonacci(number - 2)
@cachify.register(ttl = 10, verbosity = 2 if DEBUG_ENABLED else None)
def fibonacci(self, number: int):
if number == 0: return 0
elif number == 1: return 1
return self.fibonacci(number - 1) + self.fibonacci(number - 2)
# No Cache Versions
async def async_fibonacci_nc(self, number: int):
if number == 0: return 0
elif number == 1: return 1
return await self.async_fibonacci_nc(number - 1) + await self.async_fibonacci_nc(number - 2)
def fibonacci_nc(self, number: int):
if number == 0: return 0
elif number == 1: return 1
return self.fibonacci_nc(number - 1) + self.fibonacci_nc(number - 2)
async def run_tests(
start_n: int = 1,
runs: int = 10,
print_every: int = 5,
):
"""
Test that both results are the same.
"""
t = Timer(format_ms=True)
o = TestObject()
# Test Sync
st = Timer(format_ms=True)
for i in range(runs):
r = o.fibonacci(start_n+i)
d = st.duration_s
if i % print_every == 0:
logger.info(f'[Sync - {i}/{runs}] Result: {r} | Time: {d}')
logger.info(f'[Sync] Cache Average Time: {st.total_average_s(runs)} | Total Time: {st.total_s}')
logger.info(o.fibonacci.cache_info(), prefix = '[Sync] Cache Info')
# Test Async
at = Timer(format_ms=True)
for i in range(runs):
r = await o.async_fibonacci(start_n+i)
d = at.duration_s
if i % print_every == 0:
logger.info(f'[Async - {i}/{runs}] Result: {r} | Time: {d}')
logger.info(f'[Async] Cache Average Time: {at.total_average_s(runs)} | Total Time: {at.total_s}')
logger.info(await o.async_fibonacci.cache_info(), prefix = '[Async] Cache Info')
logger.info(t.total_s, prefix = 'Total Time')
# Clear the Cache
o.fibonacci.clear()
logger.info(o.fibonacci.cache_info(), prefix = '[Sync] Cache Info')
await o.async_fibonacci.clear()
logger.info(await o.async_fibonacci.cache_info(), prefix = '[Async] Cache Info')
logger.info('Testing Non-Cached Functions')
t = Timer(format_ms=True)
# Test Sync
st = Timer(format_ms=True)
for i in range(runs):
r = o.fibonacci_nc(start_n+i)
d = st.duration_s
if i % print_every == 0:
logger.info(f'[Sync - {i}/{runs}] Result: {r} | Time: {d}')
logger.info(f'[Sync] Cache Average Time: {st.total_average_s(runs)} | Total Time: {st.total_s}')
# Test Async
at = Timer(format_ms=True)
for i in range(runs):
r = await o.async_fibonacci_nc(start_n+i)
d = at.duration_s
if i % print_every == 0:
logger.info(f'[Async - {i}/{runs}] Result: {r} | Time: {d}')
logger.info(f'[Async] Cache Average Time: {at.total_average_s(runs)} | Total Time: {at.total_s}')
logger.info(t.total_s, prefix = 'Total Time')
if __name__ == '__main__':
asyncio.run(run_tests(
start_n = 5,
runs = 40,
print_every = 5,
))
API Reference
Bases: kvdb.configs.caching.KVDBCachifyConfig
The Cachify Config
METHOD | DESCRIPTION |
---|---|
__call__ |
Performs the decorator |
aadd_hit |
Adds a hit to the cache |
aadd_key_expiration |
Adds an expiration to the cache key |
aadd_key_hit |
Adds a hit to the cache key |
aadd_key_timestamp |
Adds a timestamp to the cache key |
abuild_hash_key |
Builds the key for the function |
abuild_hash_name |
Builds the name for the function |
acheck_cache_policies |
Runs the cache policies |
add_hit |
Adds a hit to the cache |
add_key_expiration |
Adds an expiration to the cache key |
add_key_hit |
Adds a hit to the cache key |
add_key_timestamp |
Adds a timestamp to the cache key |
aexpire_cache_expired_keys |
Expires the cache keys |
aretrieve |
Retrieves the value from the cache |
arun_cache_operation |
Runs the cache operation |
arun_post_call_hook |
Runs the post call hook which fires after the function is called |
arun_post_init_hook |
Runs the post init hook which fires once after the function is initialized |
aset |
Sets the value in the cache |
ashould_cache_value |
Returns whether or not the value should be cached |
ashould_disable |
Returns whether or not the function should be cached |
ashould_invalidate |
Returns whether or not the function should be invalidated |
ashould_overwrite |
Returns whether or not the value should be overwritten |
avalidate_cache_policies |
Runs the cache policies |
build_hash_key |
Builds the key for the function |
build_hash_name |
Builds the name for the function |
check_cache_policies |
Runs the cache policies |
clear |
Clears the cache |
create_async_decorator |
Creates the async wrapper |
create_sync_decorator |
Creates the sync wrapper |
decode |
Decodes the value |
decode_hit |
Decodes the hit |
encode |
Encodes the value |
encode_hit |
Encodes the hit |
expire_cache_expired_keys |
Expires the cache keys |
extract_cache_kwargs |
Extracts the cache kwargs from the kwargs |
extract_config_and_kwargs |
Extract the config that are valid for this model and returns |
extract_kwargs |
Extract the kwargs that are valid for this model |
get_encoder |
Returns the encoder |
get_key |
Gets the Key |
get_serializer |
Returns the serializer |
invalidate_cache |
Invalidates the cache |
is_silenced |
Returns whether or not the stage is silenced |
model_dump |
[v1] Support for model_dump |
model_validate |
[v1] Support for model_validate |
model_validate_json |
[v1] Support for model_validate_json |
retrieve |
Retrieves the value from the cache |
run_post_call_hook |
Runs the post call hook which fires after the function is called |
run_post_init_hook |
Runs the post init hook which fires once after the function is initialized |
safely |
Safely wraps the function |
set |
Sets the value in the cache |
should_cache_value |
Returns whether or not the value should be cached |
should_disable |
Returns whether or not cache should be disabled for the function |
should_invalidate |
Returns whether or not the function should be invalidated |
should_overwrite |
Returns whether or not the value should be overwritten |
update |
Validates and updates the kwargs |
update_config |
Update the config for the other settings |
validate_attrs |
Validates the attributes |
validate_cache_policies |
Runs the cache policies |
validate_callable |
Validates the callable |
validate_is_class_method |
Validates if the function is a class method |
validate_kws |
Validates the config |
validate_serializer |
Validate the serializer config |
validateself_config |
Validates the cachify config |
ATTRIBUTE | DESCRIPTION |
---|---|
acache_expirations |
Returns the expirations of the cache
TYPE:
|
acache_info |
Returns the info for the cache
TYPE:
|
acache_items |
Returns the items
TYPE:
|
acache_keyhits |
Returns the keyhits of the cache
TYPE:
|
acache_keys |
Returns the keys
TYPE:
|
acache_timestamps |
Returns the timestamps of the cache
TYPE:
|
acache_values |
Returns the values
TYPE:
|
anum_hits |
Returns the number of hits
TYPE:
|
anum_keys |
Returns the number of keys
TYPE:
|
cache_expirations |
Returns the expirations of the cache
TYPE:
|
cache_info |
Returns the info for the cache
TYPE:
|
cache_items |
Returns the items
TYPE:
|
cache_keyhits |
Returns the keyhits of the cache
TYPE:
|
cache_keys |
Returns the keys
TYPE:
|
cache_timestamps |
Returns the timestamps of the cache
TYPE:
|
cache_values |
Returns the values
TYPE:
|
client |
Returns the client
TYPE:
|
data |
Returns the persistent data
TYPE:
|
has_async_loop |
Checks if the current process is running in an async loop
TYPE:
|
has_post_call_hook |
Returns whether or not there is a post call hook
TYPE:
|
has_post_init_hook |
Returns whether or not there is a post init hook
TYPE:
|
is_enabled |
Returns whether or not the cache is enabled [session is available]
TYPE:
|
num_default_keys |
Returns the number of default keys
TYPE:
|
num_hits |
Returns the number of hits
TYPE:
|
num_keys |
Returns the number of keys
TYPE:
|
super_verbose |
Returns whether or not the cache is super verbose
TYPE:
|
acache_expirations
async
property
Returns the expirations of the cache
acache_keyhits
async
property
Returns the keyhits of the cache
acache_timestamps
async
property
Returns the timestamps of the cache
cache_expirations
property
Returns the expirations of the cache
cache_timestamps
property
Returns the timestamps of the cache
has_async_loop
property
Checks if the current process is running in an async loop
has_post_call_hook
property
Returns whether or not there is a post call hook
has_post_init_hook
property
Returns whether or not there is a post init hook
is_enabled
property
Returns whether or not the cache is enabled [session is available]
__call__
__call__(
function: typing.Callable[
kvdb.io.cachify.base.FuncP,
kvdb.io.cachify.base.FuncT,
]
) -> typing.Callable[
kvdb.io.cachify.base.FuncP,
typing.Union[
kvdb.io.cachify.base.FuncT,
typing.Awaitable[kvdb.io.cachify.base.FuncT],
],
]
Performs the decorator
Source code in kvdb/io/cachify/base.py
aadd_hit
async
Adds a hit to the cache
Source code in kvdb/io/cachify/base.py
aadd_key_expiration
async
Adds an expiration to the cache key
Source code in kvdb/io/cachify/base.py
aadd_key_hit
async
Adds a hit to the cache key
Source code in kvdb/io/cachify/base.py
aadd_key_timestamp
async
Adds a timestamp to the cache key
Source code in kvdb/io/cachify/base.py
abuild_hash_key
async
Builds the key for the function
Source code in kvdb/io/cachify/base.py
abuild_hash_name
async
Builds the name for the function
Source code in kvdb/io/cachify/base.py
acheck_cache_policies
async
acheck_cache_policies(
key: str,
*args,
cache_kwargs: typing.Dict[
str, typing.Union[bool, int, float, typing.Any]
] = None,
**kwargs
) -> None
Runs the cache policies
Source code in kvdb/io/cachify/base.py
add_hit
Adds a hit to the cache
add_key_expiration
Adds an expiration to the cache key
Source code in kvdb/io/cachify/base.py
add_key_hit
Adds a hit to the cache key
add_key_timestamp
Adds a timestamp to the cache key
aexpire_cache_expired_keys
async
Expires the cache keys
Source code in kvdb/io/cachify/base.py
aretrieve
async
aretrieve(
key: str,
*args,
cache_kwargs: typing.Dict[
str, typing.Union[bool, int, float, typing.Any]
] = None,
**kwargs
) -> typing.Any
Retrieves the value from the cache
Source code in kvdb/io/cachify/base.py
arun_cache_operation
async
arun_cache_operation(
cache_key: str,
value: typing.Any,
*args,
cachify_kwargs: typing.Dict[str, typing.Any] = None,
**kwargs
) -> None
Runs the cache operation
Source code in kvdb/io/cachify/base.py
arun_post_call_hook
async
arun_post_call_hook(
result: typing.Any,
*args,
is_hit: typing.Optional[bool] = None,
**kwargs
) -> None
Runs the post call hook which fires after the function is called
Source code in kvdb/io/cachify/base.py
arun_post_init_hook
async
Runs the post init hook which fires once after the function is initialized
Source code in kvdb/io/cachify/base.py
aset
async
aset(
key: str,
value: typing.Any,
*args,
cache_kwargs: typing.Dict[
str, typing.Union[bool, int, float, typing.Any]
] = None,
**kwargs
) -> None
Sets the value in the cache
Source code in kvdb/io/cachify/base.py
ashould_cache_value
async
ashould_cache_value(
val: typing.Any,
*args,
cache_kwargs: typing.Dict[str, typing.Any] = None,
**kwargs
) -> bool
Returns whether or not the value should be cached
Source code in kvdb/io/cachify/base.py
ashould_disable
async
Returns whether or not the function should be cached
Source code in kvdb/io/cachify/base.py
ashould_invalidate
async
Returns whether or not the function should be invalidated
Source code in kvdb/io/cachify/base.py
ashould_overwrite
async
Returns whether or not the value should be overwritten which is based on the overwrite_if function
Source code in kvdb/io/cachify/base.py
avalidate_cache_policies
async
avalidate_cache_policies(
key: str,
*args,
cache_kwargs: typing.Dict[
str, typing.Union[bool, int, float, typing.Any]
] = None,
**kwargs
) -> None
Runs the cache policies
Source code in kvdb/io/cachify/base.py
build_hash_key
Builds the key for the function
Source code in kvdb/io/cachify/base.py
build_hash_name
Builds the name for the function
Source code in kvdb/io/cachify/base.py
check_cache_policies
check_cache_policies(
key: str,
*args,
cache_kwargs: typing.Dict[
str, typing.Union[bool, int, float, typing.Any]
] = None,
**kwargs
) -> None
Runs the cache policies
Source code in kvdb/io/cachify/base.py
clear
Clears the cache
Source code in kvdb/io/cachify/base.py
create_async_decorator
create_async_decorator(
func: typing.Callable[
kvdb.io.cachify.base.FuncP,
kvdb.io.cachify.base.FuncT,
]
) -> typing.Callable[
kvdb.io.cachify.base.FuncP,
typing.Awaitable[kvdb.io.cachify.base.FuncT],
]
Creates the async wrapper
Source code in kvdb/io/cachify/base.py
1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 |
|
create_sync_decorator
create_sync_decorator(
func: typing.Callable[
kvdb.io.cachify.base.FuncP,
kvdb.io.cachify.base.FuncT,
]
) -> typing.Callable[
kvdb.io.cachify.base.FuncP, kvdb.io.cachify.base.FuncT
]
Creates the sync wrapper
Source code in kvdb/io/cachify/base.py
1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 |
|
decode
decode_hit
encode
encode_hit
expire_cache_expired_keys
Expires the cache keys
Source code in kvdb/io/cachify/base.py
extract_cache_kwargs
extract_cache_kwargs(
**kwargs,
) -> typing.Tuple[
typing.Dict[
str, typing.Union[bool, int, float, typing.Any]
],
typing.Dict[str, typing.Any],
]
Extracts the cache kwargs from the kwargs
Returns the cache kwargs and the remaining kwargs
Source code in kvdb/io/cachify/base.py
extract_config_and_kwargs
classmethod
extract_config_and_kwargs(
_prefix: typing.Optional[str] = None,
_include_prefix: typing.Optional[bool] = None,
_include: typing.Optional[set[str]] = None,
_exclude: typing.Optional[set[str]] = None,
_exclude_none: typing.Optional[bool] = True,
**kwargs
) -> typing.Tuple[
typing.Dict[str, typing.Any],
typing.Dict[str, typing.Any],
]
Extract the config that are valid for this model and returns the config and kwargs
RETURNS | DESCRIPTION |
---|---|
typing.Tuple[typing.Dict[str, typing.Any], typing.Dict[str, typing.Any]]
|
Tuple[Dict[str, Any], Dict[str, Any]]: The config and deduplicated kwargs |
Source code in kvdb/types/base.py
extract_kwargs
classmethod
extract_kwargs(
_prefix: typing.Optional[str] = None,
_include_prefix: typing.Optional[bool] = None,
_include: typing.Optional[set[str]] = None,
_exclude: typing.Optional[set[str]] = None,
_exclude_none: typing.Optional[bool] = True,
**kwargs
) -> typing.Dict[str, typing.Any]
Extract the kwargs that are valid for this model
Source code in kvdb/types/base.py
get_encoder
get_encoder(
serializer: typing.Optional[str] = None,
serializer_enabled: typing.Optional[bool] = True,
serializer_kwargs: typing.Optional[
typing.Dict[str, typing.Any]
] = None,
compression: typing.Optional[str] = None,
compression_level: typing.Optional[int] = None,
raise_errors: typing.Optional[bool] = False,
encoding: typing.Optional[str] = None,
decode_responses: typing.Optional[bool] = None,
**kwargs
) -> "Encoder"
Returns the encoder
Source code in kvdb/configs/base.py
get_key
get_serializer
get_serializer(
serializer: typing.Optional[str] = None,
serializer_kwargs: typing.Optional[
typing.Dict[str, typing.Any]
] = None,
compression: typing.Optional[str] = None,
compression_level: typing.Optional[int] = None,
raise_errors: typing.Optional[bool] = False,
encoding: typing.Optional[str] = None,
**kwargs
) -> "SerializerT"
Returns the serializer
Source code in kvdb/configs/base.py
invalidate_cache
Invalidates the cache
Source code in kvdb/io/cachify/base.py
is_silenced
Returns whether or not the stage is silenced
model_dump
model_dump(
*,
mode: str = "python",
include: (
set[int]
| set[str]
| dict[int, typing.Any]
| dict[str, typing.Any]
| None
) = None,
exclude: (
set[int]
| set[str]
| dict[int, typing.Any]
| dict[str, typing.Any]
| None
) = None,
by_alias: bool = False,
exclude_unset: bool = False,
exclude_defaults: bool = False,
exclude_none: bool = False,
round_trip: bool = False,
warnings: bool = True
) -> typing.Dict[str, typing.Any]
[v1] Support for model_dump
Source code in kvdb/types/base.py
model_validate
classmethod
model_validate_json
classmethod
retrieve
retrieve(
key: str,
*args,
cache_kwargs: typing.Dict[
str, typing.Union[bool, int, float, typing.Any]
] = None,
**kwargs
) -> typing.Any
Retrieves the value from the cache
Source code in kvdb/io/cachify/base.py
run_post_call_hook
run_post_call_hook(
result: typing.Any,
*args,
is_hit: typing.Optional[bool] = None,
**kwargs
) -> None
Runs the post call hook which fires after the function is called
Source code in kvdb/io/cachify/base.py
run_post_init_hook
Runs the post init hook which fires once after the function is initialized
Source code in kvdb/io/cachify/base.py
safely
Safely wraps the function
Source code in kvdb/io/cachify/base.py
set
set(
key: str,
value: typing.Any,
*args,
cache_kwargs: typing.Dict[
str, typing.Union[bool, int, float, typing.Any]
] = None,
**kwargs
) -> None
Sets the value in the cache
Source code in kvdb/io/cachify/base.py
should_cache_value
should_cache_value(
val: typing.Any,
*args,
cache_kwargs: typing.Dict[str, typing.Any] = None,
**kwargs
) -> bool
Returns whether or not the value should be cached
Source code in kvdb/io/cachify/base.py
should_disable
Returns whether or not cache should be disabled for the function
Source code in kvdb/io/cachify/base.py
should_invalidate
should_invalidate(
*args,
_hits: typing.Optional[int] = None,
cache_kwargs: typing.Dict[str, typing.Any] = None,
**kwargs
) -> bool
Returns whether or not the function should be invalidated
Source code in kvdb/io/cachify/base.py
should_overwrite
Returns whether or not the value should be overwritten which is based on the overwrite_if function
Source code in kvdb/io/cachify/base.py
update
Validates and updates the kwargs
update_config
Update the config for the other settings
Source code in kvdb/types/base.py
validate_attrs
validate_cache_policies
validate_cache_policies(
key: str,
*args,
cache_kwargs: typing.Dict[
str, typing.Union[bool, int, float, typing.Any]
] = None,
**kwargs
) -> None
Runs the cache policies
Source code in kvdb/io/cachify/base.py
validate_callable
classmethod
validate_is_class_method
Validates if the function is a class method
Source code in kvdb/io/cachify/base.py
validate_kws
classmethod
validate_kws(
values: typing.Dict[str, typing.Any],
is_update: typing.Optional[bool] = None,
) -> typing.Dict[str, typing.Any]
Validates the config
Source code in kvdb/io/cachify/base.py
validate_serializer
Validate the serializer config
Source code in kvdb/configs/base.py
validateself_config
Validates the cachify config