support caching metrics #7
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This pull request adds a comprehensive, optional metrics and monitoring system to the
advanced_cachinglibrary, including new documentation, example usage, and support for multiple exporters (InMemory, OpenTelemetry, GCP Cloud Monitoring, and custom). It introduces ametricsargument to cache decorators, enables per-function and shared metrics collection, and provides guides for custom exporters and performance best practices.Metrics & Monitoring System:
metricsargument to cache decorators (e.g.,TTLCache.cached) to enable optional instrumentation via aMetricsCollectorinterface. If provided, cache operations are automatically instrumented for hits, misses, latency, errors, memory usage, and background refreshes. (src/advanced_caching/decorators.py) [1] [2] [3]InMemoryMetrics(zero dependencies, thread-safe),NullMetrics(zero overhead, default), and exporters for OpenTelemetry and GCP Cloud Monitoring, with installation instructions and extras inpyproject.toml. (README.md,pyproject.toml) [1] [2] [3]Documentation & Examples:
docs/metrics.mdand a guide for custom exporters (docs/custom-metrics-exporters.md). [1] [2]examples/metrics_example.py,examples/shared_metrics_example.py,examples/gcp_client_sharing_example.py. [1] [2] [3]Custom Exporter Support:
MetricsCollectorprotocol, with performance tips for high-throughput scenarios. (docs/custom-metrics-exporters.md)Usability Improvements:
These changes make it easy to monitor cache performance in production, development, and testing environments, with minimal overhead and flexible exporter options.