is_correct bool 2
classes | source_code stringclasses 3
values | defect_root_cause stringclasses 3
values | eviction_analysis dict | boundary_case_results listlengths 3 3 | ttl_expiration_analysis dict | entry_lifecycle_analysis dict | distributed_cache_risk_analysis dict |
|---|---|---|---|---|---|---|---|
false | from collections import OrderedDict
import time
class TimedLRU:
def __init__(self, capacity, ttl_seconds=5):
self.capacity = capacity
self.ttl_seconds = ttl_seconds
self.entries = OrderedDict()
def put(self, key, value):
if key in self.entries:
del self.entries[key]... | Capacity enforcement applies LRU eviction without first purging expired entries, allowing expired data to occupy capacity and live data to be discarded. Wall-clock deadlines are also vulnerable to clock adjustments, and operations are not synchronized for concurrent callers. | {
"eviction_strategy": "LRU; successful reads and writes move the key to the most-recently-used end.",
"eviction_trigger": "After a write, while the entry count exceeds capacity, the least-recently-used entry is removed.",
"expired_entry_precedence": "Expired entries are not swept before capacity eviction. An exp... | [
{
"case_description": "A read occurs exactly at the stored expiration timestamp.",
"expected_behavior": "The entry is treated as expired and a miss is returned.",
"actual_behavior": "The >= check removes the entry and returns a miss.",
"passed": true
},
{
"case_description": "The cache is at... | {
"ttl_value_or_source": "The constructor defaults to a fixed 5-second TTL for each write.",
"ttl_unit": "Seconds",
"expiration_basis": "Absolute expiration timestamp computed from the write time using time.time(). Reads do not extend the deadline.",
"boundary_operator": "time.time() >= expires_at; an entry is ... | {
"lifecycle_summary": "A write stores a value and an absolute deadline, replacing any prior value for the key. A successful read updates LRU order. Reads delete an expired requested entry; capacity pressure removes the LRU entry, whether or not it has expired.",
"expiration_cleanup_behavior": "Lazy cleanup on read... | {
"risk_summary": "Wall-clock differences or adjustments can cause nodes to disagree about expiration. The implementation has no synchronization or cross-node coordination, so replicated copies can also diverge in contents and eviction order.",
"affected_scenario": "Two nodes store the same key at different local t... |
false | import time
class LFUCache:
def __init__(self, capacity, ttl_seconds=30):
self.capacity = capacity
self.ttl_seconds = ttl_seconds
self.items = {}
self.sequence = 0
def put(self, key, value):
self.sequence += 1
now = time.monotonic()
self.items[key] = {
... | The expiration comparison uses > instead of >=, so an entry remains readable at its exact deadline and may be returned stale. Shared dictionary and frequency state are also accessed without synchronization, making concurrent behavior unsafe. | {
"eviction_strategy": "LFU, with the oldest insertion used to break ties in frequency.",
"eviction_trigger": "A write that makes the item count exceed capacity first scans for expired entries, then evicts one lowest-frequency entry if still over capacity.",
"expired_entry_precedence": "Entries whose deadline is ... | [
{
"case_description": "A read occurs exactly at an entry's expiration deadline.",
"expected_behavior": "The entry is expired at the deadline and the read returns a miss.",
"actual_behavior": "The strict > comparison considers equality valid, increments the frequency, and returns the value.",
"passed... | {
"ttl_value_or_source": "The constructor configures a default fixed TTL of 30 seconds for each write.",
"ttl_unit": "Seconds",
"expiration_basis": "A per-entry absolute deadline based on time.monotonic() at insertion; reads do not refresh it.",
"boundary_operator": "time.monotonic() > expires_at; equality is t... | {
"lifecycle_summary": "A write stores a value, a monotonic deadline, a frequency initialized to one, and an insertion sequence. A successful read increments frequency. Expired entries are deleted on reads or during a capacity-triggered scan; remaining over-capacity entries are subject to LFU eviction.",
"expiratio... | {
"risk_summary": "Monotonic time avoids wall-clock jumps within one process, but monotonic deadlines are process-local and cannot be assumed comparable across nodes. Independent cache instances can also accumulate different hit counts and eviction choices.",
"affected_scenario": "A cache entry or its deadline is c... |
true | from collections import OrderedDict
from threading import RLock
from time import monotonic
class LRUCache:
def __init__(self, capacity):
if capacity < 1:
raise ValueError('capacity must be positive')
self.capacity = capacity
self.entries = OrderedDict()
self.lock = RLock... | No obvious defect was found in the local TTL, expiration-boundary, capacity-eviction, or entry-lifecycle behavior shown. The implementation does not provide distributed replication or cross-node coordination. | {
"eviction_strategy": "LRU; successful reads and writes place an entry at the most-recently-used end.",
"eviction_trigger": "Before inserting, expired entries are purged and least-recently-used entries are removed until there is room.",
"expired_entry_precedence": "Expired entries are purged before capacity evic... | [
{
"case_description": "An entry is written with a zero-second TTL and then read.",
"expected_behavior": "The entry is expired immediately and the read returns a miss.",
"actual_behavior": "The read compares the deadline with the current monotonic time using <=, deletes the entry, and returns a miss.",
... | {
"ttl_value_or_source": "Each write supplies its own ttl_seconds value; negative TTLs are rejected, while zero is allowed.",
"ttl_unit": "Seconds",
"expiration_basis": "An absolute per-entry deadline computed from the write-time monotonic clock. Reads do not extend the deadline.",
"boundary_operator": "deadlin... | {
"lifecycle_summary": "A write validates its TTL, purges expired entries, replaces any existing value for the key, evicts LRU entries if necessary, and stores a new deadline. A successful read refreshes recency; an expired requested entry is deleted and returned as a miss.",
"expiration_cleanup_behavior": "Lazy cl... | {
"risk_summary": "The lock protects only this process-local instance. Independent nodes can hold different values or eviction orders, and monotonic deadlines are not portable across processes, so this implementation alone does not ensure distributed consistency.",
"affected_scenario": "Multiple application nodes m... |
Cache Expiration and Eviction Code Verification Dataset
This dataset contains source code examples involving TTL settings, expiration checks, capacity limits, and eviction strategy interactions in distributed caches. Annotations assess whether implementations handle boundary conditions and cache entry lifecycles correctly, and analyze common defect root causes and potential risks in distributed environments. It supports training and evaluating code verification, debugging, and root-cause analysis models.
Technical Specifications
| Field | Type | Description |
|---|---|---|
| is_correct | boolean | Indicates whether the code correctly handles TTL, expiration boundaries, eviction strategies, and entry lifecycles. |
| source_code | string | Cache expiration and eviction implementation code to be verified. |
| defect_root_cause | string | Describes common implementation defect causes, or states that no obvious defect was found. |
| eviction_analysis | object | Explains cache capacity limits, eviction triggers, and the strategy used to select entries for eviction. |
| boundary_case_results | array | Validation results for boundary cases involving TTL, expiration checks, capacity limits, and concurrent interactions. |
| ttl_expiration_analysis | object | Analysis of TTL configuration, expiration criteria, and expiration-check logic. |
| entry_lifecycle_analysis | object | Analyzes cache entry state changes and cleanup behavior from insertion through expiration, eviction, or deletion. |
| distributed_cache_risk_analysis | object | Analyzes potential risks involving expiration and eviction when the code runs in a distributed environment. |
Compliance Statement
| Authorization Type | CC-BY-NC-SA 4.0 (Attribution–NonCommercial–ShareAlike) |
| Commercial Use | Requires exclusive subscription or authorization contract (monthly or per-invocation charging) |
| Privacy and Anonymization | No PII, no real company names, simulated scenarios follow industry standards |
| Compliance System | Compliant with China's Data Security Law / EU GDPR / supports enterprise data access logs |
Source & Contact
- Downloads last month
- 22