exonware-xwsystem 0.0.1.411__py3-none-any.whl → 0.1.0.3__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- exonware/__init__.py +2 -1
- exonware/conf.py +2 -2
- exonware/xwsystem/__init__.py +115 -43
- exonware/xwsystem/base.py +30 -0
- exonware/xwsystem/caching/__init__.py +39 -13
- exonware/xwsystem/caching/base.py +24 -6
- exonware/xwsystem/caching/bloom_cache.py +2 -2
- exonware/xwsystem/caching/cache_manager.py +2 -1
- exonware/xwsystem/caching/conditional.py +2 -2
- exonware/xwsystem/caching/contracts.py +85 -139
- exonware/xwsystem/caching/decorators.py +6 -19
- exonware/xwsystem/caching/defs.py +2 -1
- exonware/xwsystem/caching/disk_cache.py +2 -1
- exonware/xwsystem/caching/distributed.py +2 -1
- exonware/xwsystem/caching/errors.py +2 -1
- exonware/xwsystem/caching/events.py +110 -27
- exonware/xwsystem/caching/eviction_strategies.py +2 -2
- exonware/xwsystem/caching/external_caching_python.py +701 -0
- exonware/xwsystem/caching/facade.py +253 -0
- exonware/xwsystem/caching/factory.py +300 -0
- exonware/xwsystem/caching/fluent.py +14 -12
- exonware/xwsystem/caching/integrity.py +21 -6
- exonware/xwsystem/caching/lfu_cache.py +2 -1
- exonware/xwsystem/caching/lfu_optimized.py +18 -6
- exonware/xwsystem/caching/lru_cache.py +7 -4
- exonware/xwsystem/caching/memory_bounded.py +2 -2
- exonware/xwsystem/caching/metrics_exporter.py +2 -2
- exonware/xwsystem/caching/observable_cache.py +2 -2
- exonware/xwsystem/caching/pluggable_cache.py +2 -2
- exonware/xwsystem/caching/rate_limiter.py +2 -2
- exonware/xwsystem/caching/read_through.py +2 -2
- exonware/xwsystem/caching/secure_cache.py +81 -28
- exonware/xwsystem/caching/serializable.py +9 -7
- exonware/xwsystem/caching/stats.py +2 -2
- exonware/xwsystem/caching/tagging.py +2 -2
- exonware/xwsystem/caching/ttl_cache.py +4 -3
- exonware/xwsystem/caching/two_tier_cache.py +6 -3
- exonware/xwsystem/caching/utils.py +30 -12
- exonware/xwsystem/caching/validation.py +2 -2
- exonware/xwsystem/caching/warming.py +6 -3
- exonware/xwsystem/caching/write_behind.py +15 -6
- exonware/xwsystem/config/__init__.py +11 -17
- exonware/xwsystem/config/base.py +5 -5
- exonware/xwsystem/config/contracts.py +93 -153
- exonware/xwsystem/config/defaults.py +3 -2
- exonware/xwsystem/config/defs.py +3 -2
- exonware/xwsystem/config/errors.py +2 -5
- exonware/xwsystem/config/logging.py +12 -8
- exonware/xwsystem/config/logging_setup.py +3 -2
- exonware/xwsystem/config/performance.py +73 -391
- exonware/xwsystem/config/performance_modes.py +9 -8
- exonware/xwsystem/config/version_manager.py +1 -0
- exonware/xwsystem/config.py +27 -0
- exonware/xwsystem/console/__init__.py +53 -0
- exonware/xwsystem/console/base.py +133 -0
- exonware/xwsystem/console/cli/__init__.py +61 -0
- exonware/xwsystem/{cli → console/cli}/args.py +27 -24
- exonware/xwsystem/{cli → console/cli}/base.py +18 -87
- exonware/xwsystem/{cli → console/cli}/colors.py +15 -13
- exonware/xwsystem/console/cli/console.py +98 -0
- exonware/xwsystem/{cli → console/cli}/contracts.py +51 -69
- exonware/xwsystem/console/cli/defs.py +87 -0
- exonware/xwsystem/console/cli/encoding.py +69 -0
- exonware/xwsystem/{cli → console/cli}/errors.py +8 -3
- exonware/xwsystem/console/cli/event_logger.py +166 -0
- exonware/xwsystem/{cli → console/cli}/progress.py +25 -21
- exonware/xwsystem/{cli → console/cli}/prompts.py +3 -2
- exonware/xwsystem/{cli → console/cli}/tables.py +27 -24
- exonware/xwsystem/console/contracts.py +113 -0
- exonware/xwsystem/console/defs.py +154 -0
- exonware/xwsystem/console/errors.py +34 -0
- exonware/xwsystem/console/event_logger.py +385 -0
- exonware/xwsystem/console/writer.py +132 -0
- exonware/xwsystem/contracts.py +28 -0
- exonware/xwsystem/data_structures/__init__.py +23 -0
- exonware/xwsystem/data_structures/trie.py +34 -0
- exonware/xwsystem/data_structures/union_find.py +144 -0
- exonware/xwsystem/defs.py +17 -0
- exonware/xwsystem/errors.py +23 -0
- exonware/xwsystem/facade.py +62 -0
- exonware/xwsystem/http_client/__init__.py +22 -1
- exonware/xwsystem/http_client/advanced_client.py +8 -5
- exonware/xwsystem/http_client/base.py +3 -2
- exonware/xwsystem/http_client/client.py +7 -4
- exonware/xwsystem/http_client/contracts.py +42 -56
- exonware/xwsystem/http_client/defs.py +2 -1
- exonware/xwsystem/http_client/errors.py +2 -1
- exonware/xwsystem/http_client/facade.py +156 -0
- exonware/xwsystem/io/__init__.py +22 -3
- exonware/xwsystem/io/archive/__init__.py +8 -2
- exonware/xwsystem/io/archive/archive.py +1 -1
- exonware/xwsystem/io/archive/archive_files.py +4 -7
- exonware/xwsystem/io/archive/archivers.py +120 -10
- exonware/xwsystem/io/archive/base.py +4 -5
- exonware/xwsystem/io/archive/codec_integration.py +1 -2
- exonware/xwsystem/io/archive/compression.py +1 -2
- exonware/xwsystem/io/archive/facade.py +263 -0
- exonware/xwsystem/io/archive/formats/__init__.py +2 -3
- exonware/xwsystem/io/archive/formats/brotli_format.py +20 -7
- exonware/xwsystem/io/archive/formats/lz4_format.py +20 -7
- exonware/xwsystem/io/archive/formats/rar.py +11 -5
- exonware/xwsystem/io/archive/formats/sevenzip.py +12 -6
- exonware/xwsystem/io/archive/formats/squashfs_format.py +1 -2
- exonware/xwsystem/io/archive/formats/tar.py +52 -7
- exonware/xwsystem/io/archive/formats/wim_format.py +11 -5
- exonware/xwsystem/io/archive/formats/zip.py +1 -2
- exonware/xwsystem/io/archive/formats/zpaq_format.py +1 -2
- exonware/xwsystem/io/archive/formats/zstandard.py +20 -7
- exonware/xwsystem/io/base.py +119 -115
- exonware/xwsystem/io/codec/__init__.py +4 -2
- exonware/xwsystem/io/codec/base.py +19 -13
- exonware/xwsystem/io/codec/contracts.py +59 -2
- exonware/xwsystem/io/codec/registry.py +67 -21
- exonware/xwsystem/io/common/__init__.py +1 -1
- exonware/xwsystem/io/common/atomic.py +29 -16
- exonware/xwsystem/io/common/base.py +11 -10
- exonware/xwsystem/io/common/lock.py +6 -5
- exonware/xwsystem/io/common/path_manager.py +2 -1
- exonware/xwsystem/io/common/watcher.py +1 -2
- exonware/xwsystem/io/contracts.py +301 -433
- exonware/xwsystem/io/contracts_1.py +1180 -0
- exonware/xwsystem/io/data_operations.py +279 -14
- exonware/xwsystem/io/defs.py +4 -3
- exonware/xwsystem/io/errors.py +3 -2
- exonware/xwsystem/io/facade.py +87 -61
- exonware/xwsystem/io/file/__init__.py +1 -1
- exonware/xwsystem/io/file/base.py +8 -9
- exonware/xwsystem/io/file/conversion.py +2 -3
- exonware/xwsystem/io/file/file.py +61 -18
- exonware/xwsystem/io/file/paged_source.py +8 -8
- exonware/xwsystem/io/file/paging/__init__.py +1 -2
- exonware/xwsystem/io/file/paging/byte_paging.py +4 -5
- exonware/xwsystem/io/file/paging/line_paging.py +2 -3
- exonware/xwsystem/io/file/paging/record_paging.py +2 -3
- exonware/xwsystem/io/file/paging/registry.py +1 -2
- exonware/xwsystem/io/file/source.py +13 -17
- exonware/xwsystem/io/filesystem/__init__.py +1 -1
- exonware/xwsystem/io/filesystem/base.py +1 -2
- exonware/xwsystem/io/filesystem/local.py +3 -4
- exonware/xwsystem/io/folder/__init__.py +1 -1
- exonware/xwsystem/io/folder/base.py +1 -2
- exonware/xwsystem/io/folder/folder.py +16 -7
- exonware/xwsystem/io/indexing/__init__.py +14 -0
- exonware/xwsystem/io/indexing/facade.py +443 -0
- exonware/xwsystem/io/path_parser.py +98 -0
- exonware/xwsystem/io/serialization/__init__.py +21 -3
- exonware/xwsystem/io/serialization/auto_serializer.py +146 -20
- exonware/xwsystem/io/serialization/base.py +84 -34
- exonware/xwsystem/io/serialization/contracts.py +50 -73
- exonware/xwsystem/io/serialization/defs.py +2 -1
- exonware/xwsystem/io/serialization/errors.py +2 -1
- exonware/xwsystem/io/serialization/flyweight.py +154 -7
- exonware/xwsystem/io/serialization/format_detector.py +15 -14
- exonware/xwsystem/io/serialization/formats/__init__.py +8 -5
- exonware/xwsystem/io/serialization/formats/binary/bson.py +15 -6
- exonware/xwsystem/io/serialization/formats/binary/cbor.py +5 -5
- exonware/xwsystem/io/serialization/formats/binary/marshal.py +5 -5
- exonware/xwsystem/io/serialization/formats/binary/msgpack.py +5 -5
- exonware/xwsystem/io/serialization/formats/binary/pickle.py +5 -5
- exonware/xwsystem/io/serialization/formats/binary/plistlib.py +5 -5
- exonware/xwsystem/io/serialization/formats/database/dbm.py +7 -7
- exonware/xwsystem/io/serialization/formats/database/shelve.py +7 -7
- exonware/xwsystem/io/serialization/formats/database/sqlite3.py +7 -7
- exonware/xwsystem/io/serialization/formats/tabular/__init__.py +27 -0
- exonware/xwsystem/io/serialization/formats/tabular/base.py +89 -0
- exonware/xwsystem/io/serialization/formats/tabular/csv.py +319 -0
- exonware/xwsystem/io/serialization/formats/tabular/df.py +249 -0
- exonware/xwsystem/io/serialization/formats/tabular/excel.py +291 -0
- exonware/xwsystem/io/serialization/formats/tabular/googlesheets.py +374 -0
- exonware/xwsystem/io/serialization/formats/text/__init__.py +1 -1
- exonware/xwsystem/io/serialization/formats/text/append_only_log.py +199 -0
- exonware/xwsystem/io/serialization/formats/text/configparser.py +5 -5
- exonware/xwsystem/io/serialization/formats/text/csv.py +7 -5
- exonware/xwsystem/io/serialization/formats/text/formdata.py +5 -5
- exonware/xwsystem/io/serialization/formats/text/json.py +65 -33
- exonware/xwsystem/io/serialization/formats/text/json5.py +8 -4
- exonware/xwsystem/io/serialization/formats/text/jsonlines.py +113 -25
- exonware/xwsystem/io/serialization/formats/text/multipart.py +5 -5
- exonware/xwsystem/io/serialization/formats/text/toml.py +8 -6
- exonware/xwsystem/io/serialization/formats/text/xml.py +25 -20
- exonware/xwsystem/io/serialization/formats/text/yaml.py +8 -6
- exonware/xwsystem/io/serialization/parsers/__init__.py +16 -0
- exonware/xwsystem/io/serialization/parsers/base.py +60 -0
- exonware/xwsystem/io/serialization/parsers/hybrid_parser.py +62 -0
- exonware/xwsystem/io/serialization/parsers/msgspec_parser.py +48 -0
- exonware/xwsystem/io/serialization/parsers/orjson_direct_parser.py +54 -0
- exonware/xwsystem/io/serialization/parsers/orjson_parser.py +62 -0
- exonware/xwsystem/io/serialization/parsers/pysimdjson_parser.py +55 -0
- exonware/xwsystem/io/serialization/parsers/rapidjson_parser.py +53 -0
- exonware/xwsystem/io/serialization/parsers/registry.py +91 -0
- exonware/xwsystem/io/serialization/parsers/standard.py +44 -0
- exonware/xwsystem/io/serialization/parsers/ujson_parser.py +53 -0
- exonware/xwsystem/io/serialization/registry.py +4 -4
- exonware/xwsystem/io/serialization/serializer.py +168 -79
- exonware/xwsystem/io/serialization/universal_options.py +367 -0
- exonware/xwsystem/io/serialization/utils/__init__.py +1 -2
- exonware/xwsystem/io/serialization/utils/path_ops.py +5 -6
- exonware/xwsystem/io/source_reader.py +223 -0
- exonware/xwsystem/io/stream/__init__.py +1 -1
- exonware/xwsystem/io/stream/async_operations.py +61 -14
- exonware/xwsystem/io/stream/base.py +1 -2
- exonware/xwsystem/io/stream/codec_io.py +6 -7
- exonware/xwsystem/ipc/__init__.py +1 -0
- exonware/xwsystem/ipc/async_fabric.py +4 -4
- exonware/xwsystem/ipc/base.py +6 -5
- exonware/xwsystem/ipc/contracts.py +41 -66
- exonware/xwsystem/ipc/defs.py +2 -1
- exonware/xwsystem/ipc/errors.py +2 -1
- exonware/xwsystem/ipc/message_queue.py +5 -2
- exonware/xwsystem/ipc/pipes.py +70 -34
- exonware/xwsystem/ipc/process_manager.py +7 -5
- exonware/xwsystem/ipc/process_pool.py +6 -5
- exonware/xwsystem/ipc/shared_memory.py +64 -11
- exonware/xwsystem/monitoring/__init__.py +7 -0
- exonware/xwsystem/monitoring/base.py +11 -8
- exonware/xwsystem/monitoring/contracts.py +86 -144
- exonware/xwsystem/monitoring/defs.py +2 -1
- exonware/xwsystem/monitoring/error_recovery.py +16 -3
- exonware/xwsystem/monitoring/errors.py +2 -1
- exonware/xwsystem/monitoring/facade.py +183 -0
- exonware/xwsystem/monitoring/memory_monitor.py +1 -0
- exonware/xwsystem/monitoring/metrics.py +1 -0
- exonware/xwsystem/monitoring/performance_manager_generic.py +7 -7
- exonware/xwsystem/monitoring/performance_monitor.py +1 -0
- exonware/xwsystem/monitoring/performance_validator.py +1 -0
- exonware/xwsystem/monitoring/system_monitor.py +6 -5
- exonware/xwsystem/monitoring/tracing.py +18 -16
- exonware/xwsystem/monitoring/tracker.py +2 -1
- exonware/xwsystem/operations/__init__.py +5 -50
- exonware/xwsystem/operations/base.py +3 -44
- exonware/xwsystem/operations/contracts.py +25 -15
- exonware/xwsystem/operations/defs.py +1 -1
- exonware/xwsystem/operations/diff.py +5 -4
- exonware/xwsystem/operations/errors.py +1 -1
- exonware/xwsystem/operations/merge.py +6 -4
- exonware/xwsystem/operations/patch.py +5 -4
- exonware/xwsystem/patterns/__init__.py +1 -0
- exonware/xwsystem/patterns/base.py +2 -1
- exonware/xwsystem/patterns/context_manager.py +2 -1
- exonware/xwsystem/patterns/contracts.py +215 -256
- exonware/xwsystem/patterns/defs.py +2 -1
- exonware/xwsystem/patterns/dynamic_facade.py +1 -0
- exonware/xwsystem/patterns/errors.py +2 -4
- exonware/xwsystem/patterns/handler_factory.py +2 -3
- exonware/xwsystem/patterns/import_registry.py +1 -0
- exonware/xwsystem/patterns/object_pool.py +1 -0
- exonware/xwsystem/patterns/registry.py +4 -43
- exonware/xwsystem/plugins/__init__.py +2 -1
- exonware/xwsystem/plugins/base.py +6 -5
- exonware/xwsystem/plugins/contracts.py +94 -158
- exonware/xwsystem/plugins/defs.py +2 -1
- exonware/xwsystem/plugins/errors.py +2 -1
- exonware/xwsystem/py.typed +3 -0
- exonware/xwsystem/query/__init__.py +36 -0
- exonware/xwsystem/query/contracts.py +56 -0
- exonware/xwsystem/query/errors.py +22 -0
- exonware/xwsystem/query/registry.py +128 -0
- exonware/xwsystem/runtime/__init__.py +2 -1
- exonware/xwsystem/runtime/base.py +4 -3
- exonware/xwsystem/runtime/contracts.py +39 -60
- exonware/xwsystem/runtime/defs.py +2 -1
- exonware/xwsystem/runtime/env.py +11 -9
- exonware/xwsystem/runtime/errors.py +2 -1
- exonware/xwsystem/runtime/reflection.py +3 -2
- exonware/xwsystem/security/__init__.py +68 -11
- exonware/xwsystem/security/audit.py +167 -0
- exonware/xwsystem/security/base.py +121 -24
- exonware/xwsystem/security/contracts.py +91 -146
- exonware/xwsystem/security/crypto.py +17 -16
- exonware/xwsystem/security/defs.py +2 -1
- exonware/xwsystem/security/errors.py +2 -1
- exonware/xwsystem/security/facade.py +321 -0
- exonware/xwsystem/security/file_security.py +330 -0
- exonware/xwsystem/security/hazmat.py +11 -8
- exonware/xwsystem/security/monitor.py +372 -0
- exonware/xwsystem/security/path_validator.py +140 -18
- exonware/xwsystem/security/policy.py +357 -0
- exonware/xwsystem/security/resource_limits.py +1 -0
- exonware/xwsystem/security/validator.py +455 -0
- exonware/xwsystem/shared/__init__.py +14 -1
- exonware/xwsystem/shared/base.py +285 -2
- exonware/xwsystem/shared/contracts.py +415 -126
- exonware/xwsystem/shared/defs.py +2 -1
- exonware/xwsystem/shared/errors.py +2 -2
- exonware/xwsystem/shared/xwobject.py +316 -0
- exonware/xwsystem/structures/__init__.py +1 -0
- exonware/xwsystem/structures/base.py +3 -2
- exonware/xwsystem/structures/circular_detector.py +15 -14
- exonware/xwsystem/structures/contracts.py +53 -76
- exonware/xwsystem/structures/defs.py +2 -1
- exonware/xwsystem/structures/errors.py +2 -1
- exonware/xwsystem/structures/tree_walker.py +2 -1
- exonware/xwsystem/threading/__init__.py +21 -4
- exonware/xwsystem/threading/async_primitives.py +6 -5
- exonware/xwsystem/threading/base.py +3 -2
- exonware/xwsystem/threading/contracts.py +87 -143
- exonware/xwsystem/threading/defs.py +2 -1
- exonware/xwsystem/threading/errors.py +2 -1
- exonware/xwsystem/threading/facade.py +175 -0
- exonware/xwsystem/threading/locks.py +1 -0
- exonware/xwsystem/threading/safe_factory.py +1 -0
- exonware/xwsystem/utils/__init__.py +40 -0
- exonware/xwsystem/utils/base.py +22 -21
- exonware/xwsystem/utils/contracts.py +50 -73
- exonware/xwsystem/utils/dt/__init__.py +19 -3
- exonware/xwsystem/utils/dt/base.py +5 -4
- exonware/xwsystem/utils/dt/contracts.py +22 -29
- exonware/xwsystem/utils/dt/defs.py +2 -1
- exonware/xwsystem/utils/dt/errors.py +2 -5
- exonware/xwsystem/utils/dt/formatting.py +88 -2
- exonware/xwsystem/utils/dt/humanize.py +10 -9
- exonware/xwsystem/utils/dt/parsing.py +56 -5
- exonware/xwsystem/utils/dt/timezone_utils.py +2 -24
- exonware/xwsystem/utils/errors.py +2 -4
- exonware/xwsystem/utils/paths.py +1 -0
- exonware/xwsystem/utils/string.py +49 -0
- exonware/xwsystem/utils/test_runner.py +139 -480
- exonware/xwsystem/utils/utils_contracts.py +2 -1
- exonware/xwsystem/utils/web.py +110 -0
- exonware/xwsystem/validation/__init__.py +25 -1
- exonware/xwsystem/validation/base.py +6 -5
- exonware/xwsystem/validation/contracts.py +29 -41
- exonware/xwsystem/validation/data_validator.py +1 -0
- exonware/xwsystem/validation/declarative.py +11 -8
- exonware/xwsystem/validation/defs.py +2 -1
- exonware/xwsystem/validation/errors.py +2 -1
- exonware/xwsystem/validation/facade.py +198 -0
- exonware/xwsystem/validation/fluent_validator.py +22 -19
- exonware/xwsystem/validation/schema_discovery.py +210 -0
- exonware/xwsystem/validation/type_safety.py +2 -1
- exonware/xwsystem/version.py +4 -4
- {exonware_xwsystem-0.0.1.411.dist-info → exonware_xwsystem-0.1.0.3.dist-info}/METADATA +71 -4
- exonware_xwsystem-0.1.0.3.dist-info/RECORD +337 -0
- exonware/xwsystem/caching/USAGE_GUIDE.md +0 -779
- exonware/xwsystem/cli/__init__.py +0 -43
- exonware/xwsystem/cli/console.py +0 -113
- exonware/xwsystem/cli/defs.py +0 -134
- exonware/xwsystem/conf.py +0 -44
- exonware/xwsystem/security/auth.py +0 -484
- exonware_xwsystem-0.0.1.411.dist-info/RECORD +0 -274
- {exonware_xwsystem-0.0.1.411.dist-info → exonware_xwsystem-0.1.0.3.dist-info}/WHEEL +0 -0
- {exonware_xwsystem-0.0.1.411.dist-info → exonware_xwsystem-0.1.0.3.dist-info}/licenses/LICENSE +0 -0
|
@@ -1,17 +1,16 @@
|
|
|
1
1
|
#!/usr/bin/env python3
|
|
2
|
+
#exonware/xwsystem/src/exonware/xwsystem/caching/contracts.py
|
|
2
3
|
"""
|
|
3
4
|
Company: eXonware.com
|
|
4
5
|
Author: Eng. Muhammad AlShehri
|
|
5
6
|
Email: connect@exonware.com
|
|
6
|
-
Version: 0.0.
|
|
7
|
+
Version: 0.1.0.3
|
|
7
8
|
Generation Date: September 04, 2025
|
|
8
9
|
|
|
9
10
|
Caching protocol interfaces for XWSystem.
|
|
10
11
|
"""
|
|
11
12
|
|
|
12
|
-
from
|
|
13
|
-
from typing import Any, Optional, Union, Iterator, Callable, Protocol
|
|
14
|
-
from typing_extensions import runtime_checkable
|
|
13
|
+
from typing import Any, Optional, Iterator, Callable, Protocol, runtime_checkable
|
|
15
14
|
import time
|
|
16
15
|
|
|
17
16
|
# Import enums from types module
|
|
@@ -27,14 +26,14 @@ from .defs import (
|
|
|
27
26
|
# CACHEABLE INTERFACES
|
|
28
27
|
# ============================================================================
|
|
29
28
|
|
|
30
|
-
|
|
29
|
+
@runtime_checkable
|
|
30
|
+
class ICacheable(Protocol):
|
|
31
31
|
"""
|
|
32
32
|
Interface for cacheable objects.
|
|
33
33
|
|
|
34
34
|
Enforces consistent caching behavior across XWSystem.
|
|
35
35
|
"""
|
|
36
36
|
|
|
37
|
-
@abstractmethod
|
|
38
37
|
def cache(self, key: str, value: Any, ttl: Optional[int] = None) -> bool:
|
|
39
38
|
"""
|
|
40
39
|
Cache a value with key.
|
|
@@ -47,9 +46,8 @@ class ICacheable(ABC):
|
|
|
47
46
|
Returns:
|
|
48
47
|
True if cached successfully
|
|
49
48
|
"""
|
|
50
|
-
|
|
49
|
+
...
|
|
51
50
|
|
|
52
|
-
@abstractmethod
|
|
53
51
|
def get_cached(self, key: str, default: Any = None) -> Any:
|
|
54
52
|
"""
|
|
55
53
|
Get cached value by key.
|
|
@@ -61,16 +59,14 @@ class ICacheable(ABC):
|
|
|
61
59
|
Returns:
|
|
62
60
|
Cached value or default
|
|
63
61
|
"""
|
|
64
|
-
|
|
62
|
+
...
|
|
65
63
|
|
|
66
|
-
@abstractmethod
|
|
67
64
|
def clear_cache(self) -> None:
|
|
68
65
|
"""
|
|
69
66
|
Clear all cached values.
|
|
70
67
|
"""
|
|
71
|
-
|
|
68
|
+
...
|
|
72
69
|
|
|
73
|
-
@abstractmethod
|
|
74
70
|
def has_cached(self, key: str) -> bool:
|
|
75
71
|
"""
|
|
76
72
|
Check if key is cached.
|
|
@@ -81,9 +77,8 @@ class ICacheable(ABC):
|
|
|
81
77
|
Returns:
|
|
82
78
|
True if cached
|
|
83
79
|
"""
|
|
84
|
-
|
|
80
|
+
...
|
|
85
81
|
|
|
86
|
-
@abstractmethod
|
|
87
82
|
def remove_cached(self, key: str) -> bool:
|
|
88
83
|
"""
|
|
89
84
|
Remove cached value by key.
|
|
@@ -94,9 +89,8 @@ class ICacheable(ABC):
|
|
|
94
89
|
Returns:
|
|
95
90
|
True if removed
|
|
96
91
|
"""
|
|
97
|
-
|
|
92
|
+
...
|
|
98
93
|
|
|
99
|
-
@abstractmethod
|
|
100
94
|
def get_cache_size(self) -> int:
|
|
101
95
|
"""
|
|
102
96
|
Get number of cached items.
|
|
@@ -104,9 +98,8 @@ class ICacheable(ABC):
|
|
|
104
98
|
Returns:
|
|
105
99
|
Number of cached items
|
|
106
100
|
"""
|
|
107
|
-
|
|
101
|
+
...
|
|
108
102
|
|
|
109
|
-
@abstractmethod
|
|
110
103
|
def get_cache_info(self) -> dict[str, Any]:
|
|
111
104
|
"""
|
|
112
105
|
Get cache information.
|
|
@@ -114,21 +107,21 @@ class ICacheable(ABC):
|
|
|
114
107
|
Returns:
|
|
115
108
|
Cache information dictionary
|
|
116
109
|
"""
|
|
117
|
-
|
|
110
|
+
...
|
|
118
111
|
|
|
119
112
|
|
|
120
113
|
# ============================================================================
|
|
121
114
|
# CACHE MANAGER INTERFACES
|
|
122
115
|
# ============================================================================
|
|
123
116
|
|
|
124
|
-
|
|
117
|
+
@runtime_checkable
|
|
118
|
+
class ICacheManager(Protocol):
|
|
125
119
|
"""
|
|
126
120
|
Interface for cache management.
|
|
127
121
|
|
|
128
122
|
Enforces consistent cache management across XWSystem.
|
|
129
123
|
"""
|
|
130
124
|
|
|
131
|
-
@abstractmethod
|
|
132
125
|
def create_cache(self, name: str, max_size: int = 1000, policy: CachePolicy = CachePolicy.LRU) -> ICacheable:
|
|
133
126
|
"""
|
|
134
127
|
Create a new cache.
|
|
@@ -141,9 +134,8 @@ class ICacheManager(ABC):
|
|
|
141
134
|
Returns:
|
|
142
135
|
Cache instance
|
|
143
136
|
"""
|
|
144
|
-
|
|
137
|
+
...
|
|
145
138
|
|
|
146
|
-
@abstractmethod
|
|
147
139
|
def get_cache(self, name: str) -> Optional[ICacheable]:
|
|
148
140
|
"""
|
|
149
141
|
Get cache by name.
|
|
@@ -154,9 +146,8 @@ class ICacheManager(ABC):
|
|
|
154
146
|
Returns:
|
|
155
147
|
Cache instance or None
|
|
156
148
|
"""
|
|
157
|
-
|
|
149
|
+
...
|
|
158
150
|
|
|
159
|
-
@abstractmethod
|
|
160
151
|
def remove_cache(self, name: str) -> bool:
|
|
161
152
|
"""
|
|
162
153
|
Remove cache by name.
|
|
@@ -167,9 +158,8 @@ class ICacheManager(ABC):
|
|
|
167
158
|
Returns:
|
|
168
159
|
True if removed
|
|
169
160
|
"""
|
|
170
|
-
|
|
161
|
+
...
|
|
171
162
|
|
|
172
|
-
@abstractmethod
|
|
173
163
|
def list_caches(self) -> list[str]:
|
|
174
164
|
"""
|
|
175
165
|
List all cache names.
|
|
@@ -177,16 +167,14 @@ class ICacheManager(ABC):
|
|
|
177
167
|
Returns:
|
|
178
168
|
List of cache names
|
|
179
169
|
"""
|
|
180
|
-
|
|
170
|
+
...
|
|
181
171
|
|
|
182
|
-
@abstractmethod
|
|
183
172
|
def clear_all_caches(self) -> None:
|
|
184
173
|
"""
|
|
185
174
|
Clear all caches.
|
|
186
175
|
"""
|
|
187
|
-
|
|
176
|
+
...
|
|
188
177
|
|
|
189
|
-
@abstractmethod
|
|
190
178
|
def get_cache_stats(self) -> dict[str, dict[str, Any]]:
|
|
191
179
|
"""
|
|
192
180
|
Get statistics for all caches.
|
|
@@ -194,9 +182,8 @@ class ICacheManager(ABC):
|
|
|
194
182
|
Returns:
|
|
195
183
|
Dictionary of cache statistics
|
|
196
184
|
"""
|
|
197
|
-
|
|
185
|
+
...
|
|
198
186
|
|
|
199
|
-
@abstractmethod
|
|
200
187
|
def set_global_policy(self, policy: CachePolicy) -> None:
|
|
201
188
|
"""
|
|
202
189
|
Set global cache policy.
|
|
@@ -204,9 +191,8 @@ class ICacheManager(ABC):
|
|
|
204
191
|
Args:
|
|
205
192
|
policy: Global eviction policy
|
|
206
193
|
"""
|
|
207
|
-
|
|
194
|
+
...
|
|
208
195
|
|
|
209
|
-
@abstractmethod
|
|
210
196
|
def get_global_policy(self) -> CachePolicy:
|
|
211
197
|
"""
|
|
212
198
|
Get global cache policy.
|
|
@@ -214,21 +200,21 @@ class ICacheManager(ABC):
|
|
|
214
200
|
Returns:
|
|
215
201
|
Global eviction policy
|
|
216
202
|
"""
|
|
217
|
-
|
|
203
|
+
...
|
|
218
204
|
|
|
219
205
|
|
|
220
206
|
# ============================================================================
|
|
221
207
|
# CACHE STORAGE INTERFACES
|
|
222
208
|
# ============================================================================
|
|
223
209
|
|
|
224
|
-
|
|
210
|
+
@runtime_checkable
|
|
211
|
+
class ICacheStorage(Protocol):
|
|
225
212
|
"""
|
|
226
213
|
Interface for cache storage backends.
|
|
227
214
|
|
|
228
215
|
Enforces consistent cache storage across XWSystem.
|
|
229
216
|
"""
|
|
230
217
|
|
|
231
|
-
@abstractmethod
|
|
232
218
|
def store(self, key: str, value: Any, ttl: Optional[int] = None) -> bool:
|
|
233
219
|
"""
|
|
234
220
|
Store value in cache.
|
|
@@ -241,9 +227,8 @@ class ICacheStorage(ABC):
|
|
|
241
227
|
Returns:
|
|
242
228
|
True if stored successfully
|
|
243
229
|
"""
|
|
244
|
-
|
|
230
|
+
...
|
|
245
231
|
|
|
246
|
-
@abstractmethod
|
|
247
232
|
def retrieve(self, key: str) -> Optional[Any]:
|
|
248
233
|
"""
|
|
249
234
|
Retrieve value from cache.
|
|
@@ -254,9 +239,8 @@ class ICacheStorage(ABC):
|
|
|
254
239
|
Returns:
|
|
255
240
|
Cached value or None
|
|
256
241
|
"""
|
|
257
|
-
|
|
242
|
+
...
|
|
258
243
|
|
|
259
|
-
@abstractmethod
|
|
260
244
|
def delete(self, key: str) -> bool:
|
|
261
245
|
"""
|
|
262
246
|
Delete value from cache.
|
|
@@ -267,9 +251,8 @@ class ICacheStorage(ABC):
|
|
|
267
251
|
Returns:
|
|
268
252
|
True if deleted
|
|
269
253
|
"""
|
|
270
|
-
|
|
254
|
+
...
|
|
271
255
|
|
|
272
|
-
@abstractmethod
|
|
273
256
|
def exists(self, key: str) -> bool:
|
|
274
257
|
"""
|
|
275
258
|
Check if key exists in cache.
|
|
@@ -280,16 +263,14 @@ class ICacheStorage(ABC):
|
|
|
280
263
|
Returns:
|
|
281
264
|
True if exists
|
|
282
265
|
"""
|
|
283
|
-
|
|
266
|
+
...
|
|
284
267
|
|
|
285
|
-
@abstractmethod
|
|
286
268
|
def clear(self) -> None:
|
|
287
269
|
"""
|
|
288
270
|
Clear all cached values.
|
|
289
271
|
"""
|
|
290
|
-
|
|
272
|
+
...
|
|
291
273
|
|
|
292
|
-
@abstractmethod
|
|
293
274
|
def size(self) -> int:
|
|
294
275
|
"""
|
|
295
276
|
Get number of cached items.
|
|
@@ -297,9 +278,8 @@ class ICacheStorage(ABC):
|
|
|
297
278
|
Returns:
|
|
298
279
|
Number of cached items
|
|
299
280
|
"""
|
|
300
|
-
|
|
281
|
+
...
|
|
301
282
|
|
|
302
|
-
@abstractmethod
|
|
303
283
|
def keys(self) -> Iterator[str]:
|
|
304
284
|
"""
|
|
305
285
|
Get iterator over cache keys.
|
|
@@ -307,9 +287,8 @@ class ICacheStorage(ABC):
|
|
|
307
287
|
Yields:
|
|
308
288
|
Cache keys
|
|
309
289
|
"""
|
|
310
|
-
|
|
290
|
+
...
|
|
311
291
|
|
|
312
|
-
@abstractmethod
|
|
313
292
|
def values(self) -> Iterator[Any]:
|
|
314
293
|
"""
|
|
315
294
|
Get iterator over cache values.
|
|
@@ -317,9 +296,8 @@ class ICacheStorage(ABC):
|
|
|
317
296
|
Yields:
|
|
318
297
|
Cache values
|
|
319
298
|
"""
|
|
320
|
-
|
|
299
|
+
...
|
|
321
300
|
|
|
322
|
-
@abstractmethod
|
|
323
301
|
def items(self) -> Iterator[tuple[str, Any]]:
|
|
324
302
|
"""
|
|
325
303
|
Get iterator over cache items.
|
|
@@ -327,21 +305,21 @@ class ICacheStorage(ABC):
|
|
|
327
305
|
Yields:
|
|
328
306
|
Tuples of (key, value)
|
|
329
307
|
"""
|
|
330
|
-
|
|
308
|
+
...
|
|
331
309
|
|
|
332
310
|
|
|
333
311
|
# ============================================================================
|
|
334
312
|
# CACHE EVICTION INTERFACES
|
|
335
313
|
# ============================================================================
|
|
336
314
|
|
|
337
|
-
|
|
315
|
+
@runtime_checkable
|
|
316
|
+
class ICacheEviction(Protocol):
|
|
338
317
|
"""
|
|
339
318
|
Interface for cache eviction strategies.
|
|
340
319
|
|
|
341
320
|
Enforces consistent cache eviction across XWSystem.
|
|
342
321
|
"""
|
|
343
322
|
|
|
344
|
-
@abstractmethod
|
|
345
323
|
def should_evict(self, cache_size: int, max_size: int) -> bool:
|
|
346
324
|
"""
|
|
347
325
|
Check if eviction is needed.
|
|
@@ -353,9 +331,8 @@ class ICacheEviction(ABC):
|
|
|
353
331
|
Returns:
|
|
354
332
|
True if eviction needed
|
|
355
333
|
"""
|
|
356
|
-
|
|
334
|
+
...
|
|
357
335
|
|
|
358
|
-
@abstractmethod
|
|
359
336
|
def select_eviction_candidate(self, items: list[tuple[str, Any, float]]) -> str:
|
|
360
337
|
"""
|
|
361
338
|
Select item to evict.
|
|
@@ -366,9 +343,8 @@ class ICacheEviction(ABC):
|
|
|
366
343
|
Returns:
|
|
367
344
|
Key of item to evict
|
|
368
345
|
"""
|
|
369
|
-
|
|
346
|
+
...
|
|
370
347
|
|
|
371
|
-
@abstractmethod
|
|
372
348
|
def update_access(self, key: str, timestamp: float) -> None:
|
|
373
349
|
"""
|
|
374
350
|
Update access information for key.
|
|
@@ -377,9 +353,8 @@ class ICacheEviction(ABC):
|
|
|
377
353
|
key: Cache key
|
|
378
354
|
timestamp: Access timestamp
|
|
379
355
|
"""
|
|
380
|
-
|
|
356
|
+
...
|
|
381
357
|
|
|
382
|
-
@abstractmethod
|
|
383
358
|
def get_eviction_policy(self) -> CachePolicy:
|
|
384
359
|
"""
|
|
385
360
|
Get eviction policy.
|
|
@@ -387,9 +362,8 @@ class ICacheEviction(ABC):
|
|
|
387
362
|
Returns:
|
|
388
363
|
Eviction policy
|
|
389
364
|
"""
|
|
390
|
-
|
|
365
|
+
...
|
|
391
366
|
|
|
392
|
-
@abstractmethod
|
|
393
367
|
def set_eviction_policy(self, policy: CachePolicy) -> None:
|
|
394
368
|
"""
|
|
395
369
|
Set eviction policy.
|
|
@@ -397,9 +371,8 @@ class ICacheEviction(ABC):
|
|
|
397
371
|
Args:
|
|
398
372
|
policy: Eviction policy to set
|
|
399
373
|
"""
|
|
400
|
-
|
|
374
|
+
...
|
|
401
375
|
|
|
402
|
-
@abstractmethod
|
|
403
376
|
def get_eviction_stats(self) -> dict[str, Any]:
|
|
404
377
|
"""
|
|
405
378
|
Get eviction statistics.
|
|
@@ -407,21 +380,21 @@ class ICacheEviction(ABC):
|
|
|
407
380
|
Returns:
|
|
408
381
|
Eviction statistics dictionary
|
|
409
382
|
"""
|
|
410
|
-
|
|
383
|
+
...
|
|
411
384
|
|
|
412
385
|
|
|
413
386
|
# ============================================================================
|
|
414
387
|
# CACHE MONITORING INTERFACES
|
|
415
388
|
# ============================================================================
|
|
416
389
|
|
|
417
|
-
|
|
390
|
+
@runtime_checkable
|
|
391
|
+
class ICacheMonitor(Protocol):
|
|
418
392
|
"""
|
|
419
393
|
Interface for cache monitoring.
|
|
420
394
|
|
|
421
395
|
Enforces consistent cache monitoring across XWSystem.
|
|
422
396
|
"""
|
|
423
397
|
|
|
424
|
-
@abstractmethod
|
|
425
398
|
def record_hit(self, key: str) -> None:
|
|
426
399
|
"""
|
|
427
400
|
Record cache hit.
|
|
@@ -429,9 +402,8 @@ class ICacheMonitor(ABC):
|
|
|
429
402
|
Args:
|
|
430
403
|
key: Cache key that was hit
|
|
431
404
|
"""
|
|
432
|
-
|
|
405
|
+
...
|
|
433
406
|
|
|
434
|
-
@abstractmethod
|
|
435
407
|
def record_miss(self, key: str) -> None:
|
|
436
408
|
"""
|
|
437
409
|
Record cache miss.
|
|
@@ -439,9 +411,8 @@ class ICacheMonitor(ABC):
|
|
|
439
411
|
Args:
|
|
440
412
|
key: Cache key that was missed
|
|
441
413
|
"""
|
|
442
|
-
|
|
414
|
+
...
|
|
443
415
|
|
|
444
|
-
@abstractmethod
|
|
445
416
|
def record_set(self, key: str, size: int) -> None:
|
|
446
417
|
"""
|
|
447
418
|
Record cache set operation.
|
|
@@ -450,9 +421,8 @@ class ICacheMonitor(ABC):
|
|
|
450
421
|
key: Cache key that was set
|
|
451
422
|
size: Size of cached value
|
|
452
423
|
"""
|
|
453
|
-
|
|
424
|
+
...
|
|
454
425
|
|
|
455
|
-
@abstractmethod
|
|
456
426
|
def record_delete(self, key: str) -> None:
|
|
457
427
|
"""
|
|
458
428
|
Record cache delete operation.
|
|
@@ -460,9 +430,8 @@ class ICacheMonitor(ABC):
|
|
|
460
430
|
Args:
|
|
461
431
|
key: Cache key that was deleted
|
|
462
432
|
"""
|
|
463
|
-
|
|
433
|
+
...
|
|
464
434
|
|
|
465
|
-
@abstractmethod
|
|
466
435
|
def record_eviction(self, key: str, reason: str) -> None:
|
|
467
436
|
"""
|
|
468
437
|
Record cache eviction.
|
|
@@ -471,9 +440,8 @@ class ICacheMonitor(ABC):
|
|
|
471
440
|
key: Cache key that was evicted
|
|
472
441
|
reason: Eviction reason
|
|
473
442
|
"""
|
|
474
|
-
|
|
443
|
+
...
|
|
475
444
|
|
|
476
|
-
@abstractmethod
|
|
477
445
|
def get_hit_rate(self) -> float:
|
|
478
446
|
"""
|
|
479
447
|
Get cache hit rate.
|
|
@@ -481,9 +449,8 @@ class ICacheMonitor(ABC):
|
|
|
481
449
|
Returns:
|
|
482
450
|
Hit rate as percentage (0.0 to 1.0)
|
|
483
451
|
"""
|
|
484
|
-
|
|
452
|
+
...
|
|
485
453
|
|
|
486
|
-
@abstractmethod
|
|
487
454
|
def get_miss_rate(self) -> float:
|
|
488
455
|
"""
|
|
489
456
|
Get cache miss rate.
|
|
@@ -491,9 +458,8 @@ class ICacheMonitor(ABC):
|
|
|
491
458
|
Returns:
|
|
492
459
|
Miss rate as percentage (0.0 to 1.0)
|
|
493
460
|
"""
|
|
494
|
-
|
|
461
|
+
...
|
|
495
462
|
|
|
496
|
-
@abstractmethod
|
|
497
463
|
def get_stats(self) -> dict[str, Any]:
|
|
498
464
|
"""
|
|
499
465
|
Get cache statistics.
|
|
@@ -501,28 +467,27 @@ class ICacheMonitor(ABC):
|
|
|
501
467
|
Returns:
|
|
502
468
|
Statistics dictionary
|
|
503
469
|
"""
|
|
504
|
-
|
|
470
|
+
...
|
|
505
471
|
|
|
506
|
-
@abstractmethod
|
|
507
472
|
def reset_stats(self) -> None:
|
|
508
473
|
"""
|
|
509
474
|
Reset cache statistics.
|
|
510
475
|
"""
|
|
511
|
-
|
|
476
|
+
...
|
|
512
477
|
|
|
513
478
|
|
|
514
479
|
# ============================================================================
|
|
515
480
|
# DISTRIBUTED CACHE INTERFACES
|
|
516
481
|
# ============================================================================
|
|
517
482
|
|
|
518
|
-
|
|
483
|
+
@runtime_checkable
|
|
484
|
+
class IDistributedCache(Protocol):
|
|
519
485
|
"""
|
|
520
486
|
Interface for distributed cache operations.
|
|
521
487
|
|
|
522
488
|
Enforces consistent distributed caching across XWSystem.
|
|
523
489
|
"""
|
|
524
490
|
|
|
525
|
-
@abstractmethod
|
|
526
491
|
def get_node_id(self) -> str:
|
|
527
492
|
"""
|
|
528
493
|
Get current node ID.
|
|
@@ -530,9 +495,8 @@ class IDistributedCache(ABC):
|
|
|
530
495
|
Returns:
|
|
531
496
|
Node identifier
|
|
532
497
|
"""
|
|
533
|
-
|
|
498
|
+
...
|
|
534
499
|
|
|
535
|
-
@abstractmethod
|
|
536
500
|
def get_cluster_nodes(self) -> list[str]:
|
|
537
501
|
"""
|
|
538
502
|
Get list of cluster nodes.
|
|
@@ -540,9 +504,8 @@ class IDistributedCache(ABC):
|
|
|
540
504
|
Returns:
|
|
541
505
|
List of node IDs
|
|
542
506
|
"""
|
|
543
|
-
|
|
507
|
+
...
|
|
544
508
|
|
|
545
|
-
@abstractmethod
|
|
546
509
|
def replicate(self, key: str, value: Any, nodes: list[str]) -> bool:
|
|
547
510
|
"""
|
|
548
511
|
Replicate cache entry to nodes.
|
|
@@ -555,9 +518,8 @@ class IDistributedCache(ABC):
|
|
|
555
518
|
Returns:
|
|
556
519
|
True if replicated successfully
|
|
557
520
|
"""
|
|
558
|
-
|
|
521
|
+
...
|
|
559
522
|
|
|
560
|
-
@abstractmethod
|
|
561
523
|
def invalidate(self, key: str, nodes: list[str]) -> bool:
|
|
562
524
|
"""
|
|
563
525
|
Invalidate cache entry on nodes.
|
|
@@ -569,9 +531,8 @@ class IDistributedCache(ABC):
|
|
|
569
531
|
Returns:
|
|
570
532
|
True if invalidated successfully
|
|
571
533
|
"""
|
|
572
|
-
|
|
534
|
+
...
|
|
573
535
|
|
|
574
|
-
@abstractmethod
|
|
575
536
|
def sync_with_node(self, node_id: str) -> bool:
|
|
576
537
|
"""
|
|
577
538
|
Sync cache with specific node.
|
|
@@ -582,9 +543,8 @@ class IDistributedCache(ABC):
|
|
|
582
543
|
Returns:
|
|
583
544
|
True if synced successfully
|
|
584
545
|
"""
|
|
585
|
-
|
|
546
|
+
...
|
|
586
547
|
|
|
587
|
-
@abstractmethod
|
|
588
548
|
def get_consistency_level(self) -> str:
|
|
589
549
|
"""
|
|
590
550
|
Get cache consistency level.
|
|
@@ -592,9 +552,8 @@ class IDistributedCache(ABC):
|
|
|
592
552
|
Returns:
|
|
593
553
|
Consistency level (e.g., 'strong', 'eventual')
|
|
594
554
|
"""
|
|
595
|
-
|
|
555
|
+
...
|
|
596
556
|
|
|
597
|
-
@abstractmethod
|
|
598
557
|
def set_consistency_level(self, level: str) -> None:
|
|
599
558
|
"""
|
|
600
559
|
Set cache consistency level.
|
|
@@ -602,21 +561,21 @@ class IDistributedCache(ABC):
|
|
|
602
561
|
Args:
|
|
603
562
|
level: Consistency level
|
|
604
563
|
"""
|
|
605
|
-
|
|
564
|
+
...
|
|
606
565
|
|
|
607
566
|
|
|
608
567
|
# ============================================================================
|
|
609
568
|
# CACHE DECORATOR INTERFACES
|
|
610
569
|
# ============================================================================
|
|
611
570
|
|
|
612
|
-
|
|
571
|
+
@runtime_checkable
|
|
572
|
+
class ICacheDecorator(Protocol):
|
|
613
573
|
"""
|
|
614
574
|
Interface for cache decorators.
|
|
615
575
|
|
|
616
576
|
Enforces consistent cache decoration across XWSystem.
|
|
617
577
|
"""
|
|
618
578
|
|
|
619
|
-
@abstractmethod
|
|
620
579
|
def cache_result(self, func: Callable, ttl: Optional[int] = None, key_func: Optional[Callable] = None) -> Callable:
|
|
621
580
|
"""
|
|
622
581
|
Decorate function to cache results.
|
|
@@ -629,9 +588,8 @@ class ICacheDecorator(ABC):
|
|
|
629
588
|
Returns:
|
|
630
589
|
Decorated function
|
|
631
590
|
"""
|
|
632
|
-
|
|
591
|
+
...
|
|
633
592
|
|
|
634
|
-
@abstractmethod
|
|
635
593
|
def cache_invalidate(self, func: Callable, key_func: Optional[Callable] = None) -> Callable:
|
|
636
594
|
"""
|
|
637
595
|
Decorate function to invalidate cache.
|
|
@@ -643,9 +601,8 @@ class ICacheDecorator(ABC):
|
|
|
643
601
|
Returns:
|
|
644
602
|
Decorated function
|
|
645
603
|
"""
|
|
646
|
-
|
|
604
|
+
...
|
|
647
605
|
|
|
648
|
-
@abstractmethod
|
|
649
606
|
def cache_clear(self, func: Callable) -> Callable:
|
|
650
607
|
"""
|
|
651
608
|
Decorate function to clear cache.
|
|
@@ -656,9 +613,8 @@ class ICacheDecorator(ABC):
|
|
|
656
613
|
Returns:
|
|
657
614
|
Decorated function
|
|
658
615
|
"""
|
|
659
|
-
|
|
616
|
+
...
|
|
660
617
|
|
|
661
|
-
@abstractmethod
|
|
662
618
|
def cache_conditional(self, func: Callable, condition: Callable[[Any], bool]) -> Callable:
|
|
663
619
|
"""
|
|
664
620
|
Decorate function with conditional caching.
|
|
@@ -670,21 +626,21 @@ class ICacheDecorator(ABC):
|
|
|
670
626
|
Returns:
|
|
671
627
|
Decorated function
|
|
672
628
|
"""
|
|
673
|
-
|
|
629
|
+
...
|
|
674
630
|
|
|
675
631
|
|
|
676
632
|
# ============================================================================
|
|
677
633
|
# CACHE PERSISTENCE INTERFACES
|
|
678
634
|
# ============================================================================
|
|
679
635
|
|
|
680
|
-
|
|
636
|
+
@runtime_checkable
|
|
637
|
+
class ICachePersistence(Protocol):
|
|
681
638
|
"""
|
|
682
639
|
Interface for cache persistence.
|
|
683
640
|
|
|
684
641
|
Enforces consistent cache persistence across XWSystem.
|
|
685
642
|
"""
|
|
686
643
|
|
|
687
|
-
@abstractmethod
|
|
688
644
|
def save_cache(self, cache_name: str, file_path: str) -> bool:
|
|
689
645
|
"""
|
|
690
646
|
Save cache to file.
|
|
@@ -696,9 +652,8 @@ class ICachePersistence(ABC):
|
|
|
696
652
|
Returns:
|
|
697
653
|
True if saved successfully
|
|
698
654
|
"""
|
|
699
|
-
|
|
655
|
+
...
|
|
700
656
|
|
|
701
|
-
@abstractmethod
|
|
702
657
|
def load_cache(self, cache_name: str, file_path: str) -> bool:
|
|
703
658
|
"""
|
|
704
659
|
Load cache from file.
|
|
@@ -710,9 +665,8 @@ class ICachePersistence(ABC):
|
|
|
710
665
|
Returns:
|
|
711
666
|
True if loaded successfully
|
|
712
667
|
"""
|
|
713
|
-
|
|
668
|
+
...
|
|
714
669
|
|
|
715
|
-
@abstractmethod
|
|
716
670
|
def backup_cache(self, cache_name: str, backup_path: str) -> bool:
|
|
717
671
|
"""
|
|
718
672
|
Backup cache to file.
|
|
@@ -724,9 +678,8 @@ class ICachePersistence(ABC):
|
|
|
724
678
|
Returns:
|
|
725
679
|
True if backed up successfully
|
|
726
680
|
"""
|
|
727
|
-
|
|
681
|
+
...
|
|
728
682
|
|
|
729
|
-
@abstractmethod
|
|
730
683
|
def restore_cache(self, cache_name: str, backup_path: str) -> bool:
|
|
731
684
|
"""
|
|
732
685
|
Restore cache from backup.
|
|
@@ -738,9 +691,8 @@ class ICachePersistence(ABC):
|
|
|
738
691
|
Returns:
|
|
739
692
|
True if restored successfully
|
|
740
693
|
"""
|
|
741
|
-
|
|
694
|
+
...
|
|
742
695
|
|
|
743
|
-
@abstractmethod
|
|
744
696
|
def get_persistence_format(self) -> str:
|
|
745
697
|
"""
|
|
746
698
|
Get persistence format.
|
|
@@ -748,9 +700,8 @@ class ICachePersistence(ABC):
|
|
|
748
700
|
Returns:
|
|
749
701
|
Format name (e.g., 'pickle', 'json')
|
|
750
702
|
"""
|
|
751
|
-
|
|
703
|
+
...
|
|
752
704
|
|
|
753
|
-
@abstractmethod
|
|
754
705
|
def set_persistence_format(self, format_name: str) -> None:
|
|
755
706
|
"""
|
|
756
707
|
Set persistence format.
|
|
@@ -758,14 +709,15 @@ class ICachePersistence(ABC):
|
|
|
758
709
|
Args:
|
|
759
710
|
format_name: Format name
|
|
760
711
|
"""
|
|
761
|
-
|
|
712
|
+
...
|
|
762
713
|
|
|
763
714
|
|
|
764
715
|
# ============================================================================
|
|
765
716
|
# BASIC CACHE INTERFACE
|
|
766
717
|
# ============================================================================
|
|
767
718
|
|
|
768
|
-
|
|
719
|
+
@runtime_checkable
|
|
720
|
+
class ICache(Protocol):
|
|
769
721
|
"""
|
|
770
722
|
Basic cache interface for disk-based and specialized caches.
|
|
771
723
|
|
|
@@ -776,35 +728,29 @@ class ICache(ABC):
|
|
|
776
728
|
use string keys (like disk caches and two-tier caches).
|
|
777
729
|
"""
|
|
778
730
|
|
|
779
|
-
@abstractmethod
|
|
780
731
|
def get(self, key: str) -> Optional[Any]:
|
|
781
732
|
"""Get value from cache."""
|
|
782
|
-
|
|
733
|
+
...
|
|
783
734
|
|
|
784
|
-
@abstractmethod
|
|
785
735
|
def set(self, key: str, value: Any, ttl: Optional[int] = None) -> bool:
|
|
786
736
|
"""Set value in cache."""
|
|
787
|
-
|
|
737
|
+
...
|
|
788
738
|
|
|
789
|
-
@abstractmethod
|
|
790
739
|
def delete(self, key: str) -> bool:
|
|
791
740
|
"""Delete value from cache."""
|
|
792
|
-
|
|
741
|
+
...
|
|
793
742
|
|
|
794
|
-
@abstractmethod
|
|
795
743
|
def clear(self) -> bool:
|
|
796
744
|
"""Clear all cached values."""
|
|
797
|
-
|
|
745
|
+
...
|
|
798
746
|
|
|
799
|
-
@abstractmethod
|
|
800
747
|
def exists(self, key: str) -> bool:
|
|
801
748
|
"""Check if key exists in cache."""
|
|
802
|
-
|
|
749
|
+
...
|
|
803
750
|
|
|
804
|
-
@abstractmethod
|
|
805
751
|
def size(self) -> int:
|
|
806
752
|
"""Get number of cached items."""
|
|
807
|
-
|
|
753
|
+
...
|
|
808
754
|
|
|
809
755
|
|
|
810
756
|
# ============================================================================
|
|
@@ -812,8 +758,8 @@ class ICache(ABC):
|
|
|
812
758
|
# ============================================================================
|
|
813
759
|
|
|
814
760
|
@runtime_checkable
|
|
815
|
-
class
|
|
816
|
-
"""Protocol for objects that support caching."""
|
|
761
|
+
class ICacheableSimple(Protocol):
|
|
762
|
+
"""Protocol for objects that support caching (simpler interface than ICacheable)."""
|
|
817
763
|
|
|
818
764
|
def get(self, key: str, default: Any = None) -> Any:
|
|
819
765
|
"""Get value from cache."""
|