Temporally Disjointed Cache: A Deep Dive
A temporally disjointed cache is a caching strategy designed to handle situations where data access patterns exhibit low temporal locality. Let's break down what that means and how this cache works.
Understanding the Problem: Temporal Locality
Most caching strategies (like Least Recently Used - LRU) rely heavily on temporal locality. Temporal locality is the principle that if a piece of data is accessed, it's likely to be accessed again soon. Think about reading a webpage: you're likely to re-read parts of it shortly after initially viewing them. LRU works well because it keeps recently used items in the cache, assuming they'll be needed again.
However, some workloads don't exhibit strong temporal locality. Consider these scenarios:
- One-time scans: You read a large dataset once and never touch it again. (e.g., processing log files, running a report).
- Unique item access: Each request is for a different, rarely repeated item. (e.g., accessing a huge catalog of infrequently purchased products).
- Sequential access with large gaps: You access data in a sequence, but the gaps between accesses are so large that the data is likely evicted from a traditional cache before being needed again.
In these cases, a traditional cache like LRU can be counterproductive. It fills up with data that will never be reused, evicting potentially useful data that might be accessed later.
How Temporally Disjointed Caching Works
Temporally disjointed caching aims to address this by avoiding premature eviction of potentially useful data even if it hasn't been accessed recently. It does this by:
-
Dividing the Cache: The cache is divided into multiple, independent partitions (or segments). Think of it like having several smaller caches operating in parallel.
-
Random Assignment: Incoming data items are assigned to a partition randomly (or using a hash function that distributes items evenly). This is the key difference from traditional caches.
-
Independent Replacement Policies: Each partition has its own replacement policy (e.g., LRU, FIFO). Crucially, items are only evicted within their assigned partition. Items in one partition are not affected by accesses in other partitions.
Why this helps with low temporal locality:
- Reduced Interference: Because partitions are independent, a one-time access to a large number of items doesn't immediately evict everything else. Items that might be accessed later have a better chance of staying in the cache.
- Increased Hit Rate (in some cases): If there's even a small chance of re-accessing an item, the random assignment gives it a chance to stay in a partition long enough to be hit.
- Better Utilization: The cache is used more effectively because it doesn't get filled with "dead" data that's immediately evicted.
Example:
Imagine a cache with 4 partitions (P1, P2, P3, P4).
- Item A is requested -> assigned to P1.
- Item B is requested -> assigned to P2.
- Item C is requested -> assigned to P3.
- ...Item Z is requested -> assigned to P4.
Now, if you only access A-Z once, a traditional LRU cache would likely evict everything after Z is accessed.
With a temporally disjointed cache, A, B, C, and Z are still in their respective partitions. If you later request Item C again, it will be a hit in P3.
Key Parameters & Considerations:
- Number of Partitions: The optimal number of partitions depends on the workload. More partitions generally improve performance for low temporal locality, but also increase overhead.
- Partition Size: The size of each partition affects the effectiveness of the replacement policy within that partition.
- Replacement Policy: You can use different replacement policies within each partition. LRU is common, but FIFO or other policies might be suitable.
- Overhead: Managing multiple partitions adds some overhead compared to a single cache.
When to Use Temporally Disjointed Caching:
- Workloads with low temporal locality: As described above.
- Large working sets: When the total amount of data you might need to access is much larger than the cache size.
- Read-mostly workloads: Where writes are infrequent.
Comparison to Other Caching Strategies:
| Feature | LRU | Temporally Disjointed |
|---|
| Temporal Locality Assumption | Strong | Weak |
| Partitioning | Single Cache | Multiple Independent Partitions |
| Replacement Policy | Global (across entire cache) | Local (within each partition) |
| Performance (Low Temporal Locality) | Poor | Good |
| Performance (High Temporal Locality) | Excellent | Slightly worse than LRU |
| Complexity | Simple | Moderate |
Implementations & Research:
Temporally disjointed caching has been studied in academic research for several decades. There are various implementations and variations. Some related concepts include:
- Segmented LRU (SLRU): A specific implementation of temporally disjointed caching.
- Clock Pro: Another variation that aims to improve performance.
In conclusion:
Temporally disjointed caching is a valuable technique for improving cache performance in scenarios where traditional caching strategies struggle due to low temporal locality. By dividing the cache into independent partitions and using random assignment, it avoids premature eviction and increases the chances of hitting useful data. It's a more complex approach than simple LRU, but it can provide significant benefits in the right circumstances.