---
title: "mova-serve-cache — Mova code model"
description: "Mova code model of tools/mova-serve/src/cache.rs: components with their labels, obernants and the model text."
url: "https://groupants.elamur.ai/free/en/mova/tools/mova-serve/src/cache.rs.groupant/"
---
Elamur: [Mova](https://md.mova.elamur.ai/free/en/) · [Dictionary](https://md.dictionary.elamur.ai/free/en/) · [Translate](https://md.translate.elamur.ai/free/en/) · [Research](https://md.research.elamur.ai/free/en/) · **Groupants**

This page as HTML: <https://groupants.elamur.ai/free/en/mova/tools/mova-serve/src/cache.rs.groupant/>

# mova-serve-cache

The groupant beside tools/mova-serve/src/cache.rs in the Mova repository: what the code computes, what it never does, how to go back from its outputs, its invariants, cost and checks.

## Facts

- **kind:** groupant
- **status:** partial source bound model
- **source:** [`tools/mova-serve/src/cache.rs`](https://github.com/ElamurAI/mova-free/blob/main/tools/mova-serve/src/cache.rs)
- **repository folder:** [`tools/mova-serve/src/cache.rs.groupant`](https://github.com/ElamurAI/mova-free/tree/main/tools/mova-serve/src/cache.rs.groupant)

> **Implementation material.** A Mova code model describes this code at one source revision: partial models, finite checks and their stated scope. It is not a reviewed general exposition, and its labels are shown as written, never raised.

## Components

| component | label | where |
|---|---|---|
| **Approximant** | partial | [Approximant](#approximant) |
| **Ast** | partial | `syntax.json` |
| **Cost** | symbolic source derived | [Cost](#cost) |
| **Descriptant** | present | [Descriptant](#descriptant) |
| **Invariant** | partial | [Invariant](#invariant) |
| **Tests** | executed bounded checks | [Tests](#tests) |

## Obernants

The typed relations around the forward model: the behaviour complement (what the code never does), the reverse reconstruction (every input compatible with an output) and specialised views.

| relation | type | label | where |
|---|---|---|---|
| Behavior complement | behavior complement | partial source derived model | [Behavior complement](#behavior-complement) |
| Reverse reconstruction | reverse reconstruction | partial source derived model | [Reverse reconstruction](#reverse-reconstruction) |
| Model presence | model presence | partial source derived model | [Model presence](#model-presence) |

## Model text


### Descriptant

A byte-bounded cache with W-TinyLFU admission (Einziger, Friedman & Manes 2017): a 1% window LRU, a segmented main
LRU (probation 20%, protected 80%), and a count-min sketch of 4-bit counters halved every 10 × width accesses.

### Approximant

`insert → window; window overflow → candidate; admit iff freq(candidate) > freq(victim)`; `get: probation hit →
protected; protected overflow → probation`.

### Invariant

Bytes ≤ capacity after every call; each key in exactly one segment; the eviction order is a function of the call
sequence (ticks, fixed seeds, ordered maps).

### Cost

O(log n) a call; a sketch reset O(width) every 10 × width accesses.

### Behavior complement

No expiry by time, no thread safety of its own (the caller holds a mutex), no doorkeeper filter.

### Reverse reconstruction

`top` recovers the protected-first order of keys; the stats recover hits, misses, admissions, rejections and
evictions.

### Model presence

`Cache::lru` is the same structure with admission and the protected segment off: the negative control.

### Tests

`cache::tests`: a one-off flood of 5 000 unique keys keeps all 20 popular keys under W-TinyLFU and evicts all 20
under the plain LRU control; the size bound over a skewed stream of 20 000 calls and two identical runs; aging after
five halvings; oversized values refused.

## Provenance

- **source SHA-256:** `f9e5936faf631bce…`
- **repository commit:** `2e25d7bfae9a`
