← open_datasets
caching strategy implementationpython · communitycommunity · karma-rewarded● active

LRU/LFU/FIFO Cache Implementation Validator

sponsor: Platform
connect to contribute →

Each item is a lru/lfu/fifo cache implementation validator example providing Task description, Cache policy, Policy description, Policy parameters (curator-authored ground truth, JSON), Cache implementation (Python), Operation sequence. Favour realistic, self-contained cases; avoid duplicating public benchmark examples or trivial ones.

karma / item
40 karma
capacity reserved / target
38 / 5,000
final accepted
38
contributors
1
license
CC-BY-4.0
Karma per final accepted item

Secured after final acceptance. It is added to your balance when this pool publishes after its shared review window closes cleanly. Rejected items do not qualify.

secured on acceptance40 karma
Community terms

Platform-authored spec, open on delivery.

publishes tohugging face
licenseCC-BY-4.0
Quality signals

Measured pipeline stats for this dataset. A dash means the platform does not publish that measure for this pool.

submitted items65
rejected items27
duplicate rate60%
contributors1
validators1

// dataset_type_samples

Illustrative samples authored for the Caching Strategy Implementation dataset type.

operations
[
  {
    "op": "put",
    "key": "cfg-001",
    "value": {
      "key": "cfg-1",
      "value": "enabled-0"
    },
    "expected_evicted_key": null
  },
  {
    "op": "put",
    "key": "cfg-002",
    "value": {
      "key": "cfg-2",
      "value": 11
    },
    "expected_evicted_key": null
  },
  {
    "op": "put",
    "key": "cfg-003",
    "value": {
      "key": "cfg-3",
      "value": "enabled-2"
    },
    "expected_evicted_key": null
  },
  {
    "op": "get",
    "key": "cfg-001",
    "expected_result": "hit",
    "expected_value": {
      "key": "cfg-1",
      "value": "enabled-0"
    }
  },
  {
    "op": "put",
    "key": "cfg-004",
    "value": {
      "key": "cfg-4",
      "value": 13
    },
    "expected_evicted_key": "cfg-002"
  },
  {
    "op": "get",
    "key": "cfg-002",
    "expected_result": "miss"
  },
  {
    "op": "get",
    "key": "cfg-003",
    "expected_result": "hit",
    "expected_value": {
      "key": "cfg-3",
      "value": "enabled-2"
    }
  },
  {
    "op": "put",
    "key": "cfg-001",
    "value": {
      "updated": true,
      "marker": "cfg-001-v2"
    },
    "expected_evicted_key": null
  },
  {
    "op": "get",
    "key": "cfg-001",
    "expected_result": "hit",
    "expected_value": {
      "updated": true,
      "marker": "cfg-001-v2"
    }
  },
  {
    "op": "check_store",
    "key": "cfg-002",
    "expected_present": true,
    "expected_value": {
      "key": "cfg-2",
      "value": 11
    }
  },
  {
    "op": "check_store",
    "key": "cfg-never-used",
    "expected_present": false
  }
]
cache_policywrite_through
policy_params
{
  "capacity": 3
}
solution_code
# write-through cache -- config-value cache, capacity 3
class Cache:
    def __init__(self):
        self._capacity = 3
        self._value = {}
        self._last_used = {}
        self._seq = 0
        self._store = {}  # separate, permanent backing store -- never pruned by eviction

    def _bump(self, key):
        self._seq += 1
        self._last_used[key] = self._seq

    def get(self, key, now):
        if key not in self._value:
            return (False, None)
        self._bump(key)
        return (True, self._value[key])

    def get_from_store(self, key):
        if key not in self._store:
            return (False, None)
        return (True, self._store[key])

    def put(self, key, value, now, ttl_seconds=None):
        self._store[key] = value
        if key in self._value:
            self._value[key] = value
            self._bump(key)
            return None
        evicted = None
        if len(self._value) >= self._capacity:
            evicted = min(self._last_used, key=lambda k: self._last_used[k])
            del self._value[evicted]
            del self._last_used[evicted]
        self._value[key] = value
        self._bump(key)
        return evicted
task_description
A config-value cache in front of a slow, centralized config-service call, keyed by config key, for a small backend service.
policy_description
Write-through cache, capacity 3: identical eviction semantics to LRU (capacity, LRU-ordered, no ties); every put (insert or update) synchronously writes (key, value) into a separate, permanent backing store that a capacity-triggered cache eviction never prunes; get() consults only the in-memory cache layer, never the backing store.

// sample_item

Approved public samples for this Caching Strategy Implementation dataset. These are source artifacts attached to this program, not generated examples.

No public sample item is available for this dataset yet.
Ready to contribute to this dataset?
Contribute to this open pool. 40 karma is secured on each final acceptance and added to your balance after verified publication.
connect to contribute →