You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
docs: enhance README.md with improved structure and content, adding table of contents, visual aids, and sections for configuration and contribution guidelines
The Sliding Window Cache is a high-performance caching library designed for scenarios where data is accessed in sequential or predictable patterns across ranges. It automatically prefetches and maintains a "window" of data around the most recently requested range, significantly reducing the need for repeated data source queries.
10
36
@@ -19,7 +45,7 @@ The Sliding Window Cache is a high-performance caching library designed for scen
19
45
20
46
---
21
47
22
-
## Sliding Window Cache Concept
48
+
## 🎯 Sliding Window Cache Concept
23
49
24
50
Traditional caches work with individual keys. A sliding window cache, in contrast, operates on **continuous ranges** of data:
25
51
@@ -29,14 +55,74 @@ Traditional caches work with individual keys. A sliding window cache, in contras
29
55
4.**Window automatically rebalances** when the user moves outside threshold boundaries
30
56
31
57
This pattern is ideal for:
58
+
32
59
- Time-series data (sensor readings, logs, metrics)
33
60
- Paginated datasets with forward/backward navigation
34
61
- Sequential data processing (video frames, audio samples)
35
62
- Any scenario with high spatial or temporal locality of access
36
63
37
64
---
38
65
39
-
## Materialization for Fast Access
66
+
## 🔍 Understanding the Sliding Window
67
+
68
+
### Visual: Requested Range vs. Cache Window
69
+
70
+
When you request a range, the cache actually fetches and stores a larger window:
71
+
72
+
```
73
+
Requested Range (what user asks for):
74
+
[======== USER REQUEST ========]
75
+
76
+
Actual Cache Window (what cache stores):
77
+
[=== LEFT BUFFER ===][======== USER REQUEST ========][=== RIGHT BUFFER ===]
The **left** and **right buffers** are calculated as multiples of the requested range size using the `leftCacheSize` and `rightCacheSize` coefficients.
82
+
83
+
### Visual: Rebalance Trigger
84
+
85
+
Rebalancing occurs when a new request moves outside the threshold boundaries:
**Key insight:** Threshold percentages are calculated based on the **total cache window size**, not individual buffer sizes.
122
+
123
+
---
124
+
125
+
## 💾 Materialization for Fast Access
40
126
41
127
### Why Materialization?
42
128
@@ -108,7 +194,7 @@ The cache supports two materialization strategies, configured at creation time v
108
194
109
195
---
110
196
111
-
## Usage Example
197
+
## 🚀 Usage Example
112
198
113
199
```csharp
114
200
usingSlidingWindowCache;
@@ -147,16 +233,87 @@ foreach (var item in data.Span)
147
233
148
234
---
149
235
150
-
## Configuration
236
+
## ⚙️ Configuration
237
+
238
+
The `WindowCacheOptions` class provides fine-grained control over cache behavior. Understanding these parameters is essential for optimal performance.
239
+
240
+
### Configuration Parameters
241
+
242
+
#### Cache Size Coefficients
243
+
244
+
**`leftCacheSize`** (double, default: 1.0)
245
+
-**Definition**: Multiplier applied to the requested range size to determine the left buffer size
246
+
-**Practical meaning**: How much data to prefetch *before* the requested range
247
+
-**Example**: If user requests 100 items and `leftCacheSize = 1.5`, the cache prefetches 150 items to the left
248
+
-**Typical values**: 0.5 to 2.0 (depending on backward navigation patterns)
249
+
250
+
**`rightCacheSize`** (double, default: 2.0)
251
+
-**Definition**: Multiplier applied to the requested range size to determine the right buffer size
252
+
-**Practical meaning**: How much data to prefetch *after* the requested range
253
+
-**Example**: If user requests 100 items and `rightCacheSize = 2.0`, the cache prefetches 200 items to the right
254
+
-**Typical values**: 1.0 to 3.0 (higher for forward-scrolling scenarios)
255
+
256
+
#### Threshold Policies
257
+
258
+
**`leftThreshold`** (double, default: 0.2)
259
+
-**Definition**: Percentage of the **total cache window size** that triggers rebalancing when crossed on the left
260
+
-**Calculation**: `leftThreshold × (Left Buffer + Requested Range + Right Buffer)`
261
+
-**Example**: With total window of 400 items and `leftThreshold = 0.2`, rebalance triggers when user moves within 80 items of the left edge
262
+
-**Typical values**: 0.15 to 0.3 (lower = more aggressive rebalancing)
151
263
152
-
See `WindowCacheOptions` for detailed configuration parameters:
153
-
-**Left/Right Cache Coefficients**: Control how much extra data to prefetch
154
-
-**Threshold Policies**: Define when rebalancing should occur
155
-
-**Debounce Delay**: Prevent thrashing during rapid access pattern changes
264
+
**`rightThreshold`** (double, default: 0.2)
265
+
-**Definition**: Percentage of the **total cache window size** that triggers rebalancing when crossed on the right
266
+
-**Calculation**: `rightThreshold × (Left Buffer + Requested Range + Right Buffer)`
267
+
-**Example**: With total window of 400 items and `rightThreshold = 0.2`, rebalance triggers when user moves within 80 items of the right edge
268
+
-**Typical values**: 0.15 to 0.3 (lower = more aggressive rebalancing)
269
+
270
+
**⚠️ Critical Understanding**: Thresholds are **NOT** calculated against individual buffer sizes. They represent a percentage of the **entire cache window** (left buffer + requested range + right buffer). See [Understanding the Sliding Window](#-understanding-the-sliding-window) for visual examples.
271
+
272
+
#### Debouncing
273
+
274
+
**`debounceDelay`** (TimeSpan, default: 50ms)
275
+
-**Definition**: Minimum time delay before executing a rebalance operation after it's triggered
276
+
-**Purpose**: Prevents cache thrashing when user rapidly changes access patterns
277
+
-**Behavior**: If multiple rebalance requests occur within the debounce window, only the last one executes
278
+
-**Typical values**: 20ms to 200ms (depending on data source latency)
279
+
-**Trade-off**: Higher values reduce rebalance frequency but may delay cache optimization
280
+
281
+
### Configuration Examples
282
+
283
+
**Forward-heavy scrolling** (e.g., log viewer, video player):
-`RebalanceExecutionFailed` - **⚠️ CRITICAL**: Rebalance execution failures (MUST be logged)
255
-
-`RebalanceSkippedNoRebalanceRange` - Rebalances skipped due to threshold policy
256
-
-`RebalanceSkippedSameRange` - Rebalances skipped due to same-range optimization
257
-
258
384
### Zero-Cost Abstraction
259
385
260
386
If no diagnostics instance is provided (default), the cache uses `NoOpDiagnostics` - a zero-overhead implementation with empty method bodies that the JIT compiler can optimize away completely. This ensures diagnostics add zero performance overhead when not used.
**For complete metric descriptions, custom implementations, and advanced patterns, see [Diagnostics Guide](docs/diagnostics.md).**
271
389
272
390
---
273
391
274
-
## Documentation
392
+
## 📚 Documentation
275
393
276
394
For detailed architectural documentation, see:
277
395
396
+
### Mathematical Foundations
397
+
-**[Intervals.NET](https://github.com/blaze6950/Intervals.NET)** - Robust interval and range handling library that underpins cache logic. See README and documentation for core concepts like `Range`, `Domain`, `RangeData`, and interval operations.
398
+
278
399
### Core Architecture
279
400
280
401
-**[Invariants](docs/invariants.md)** - Complete list of system invariants and guarantees
@@ -315,7 +436,7 @@ For detailed architectural documentation, see:
315
436
316
437
---
317
438
318
-
## Performance Considerations
439
+
## ⚡ Performance Considerations
319
440
320
441
-**Snapshot mode**: O(1) reads, but O(n) rebalance with array allocation
321
442
-**CopyOnRead mode**: O(n) reads (copy cost), but cheaper rebalance operations
@@ -325,7 +446,7 @@ For detailed architectural documentation, see:
325
446
326
447
---
327
448
328
-
## CI/CD & Package Information
449
+
## 🔧 CI/CD & Package Information
329
450
330
451
### Continuous Integration
331
452
@@ -342,8 +463,6 @@ This project uses GitHub Actions for automated testing and deployment:
342
463
- Publishes to NuGet.org with skip-duplicate
343
464
- Stores package artifacts in workflow runs
344
465
345
-
See [.github/workflows/README.md](.github/workflows/README.md) for detailed workflow documentation.
346
-
347
466
### WebAssembly Support
348
467
349
468
SlidingWindowCache is validated for WebAssembly compatibility:
This project is a **personal R&D and engineering exploration** focused on cache design patterns, concurrent systems architecture, and performance optimization. While it's primarily a research endeavor, feedback and community input are highly valued and welcomed.
504
+
505
+
### We Welcome
506
+
507
+
-**Bug reports** - Found an issue? Please open a GitHub issue with reproduction steps
508
+
-**Feature suggestions** - Have ideas for improvements? Start a discussion or open an issue
509
+
-**Performance insights** - Benchmarked the cache in your scenario? Share your findings
510
+
-**Architecture feedback** - Thoughts on the design patterns or implementation? Let's discuss
511
+
-**Documentation improvements** - Found something unclear? Contributions to docs are appreciated
512
+
-**Positive feedback** - If the library is useful to you, that's great to know!
513
+
514
+
### How to Contribute
515
+
516
+
-**Issues**: Use [GitHub Issues](https://github.com/blaze6950/SlidingWindowCache/issues) for bugs, feature requests, or questions
517
+
-**Discussions**: Use [GitHub Discussions](https://github.com/blaze6950/SlidingWindowCache/discussions) for broader topics, ideas, or design conversations
518
+
-**Pull Requests**: Code contributions are welcome, but please open an issue first to discuss significant changes
519
+
520
+
This project benefits from community feedback while maintaining a focused research direction. All constructive input helps improve the library's design, implementation, and documentation.
0 commit comments