cache.bend checks
raw source on the hub · import bend-kit-cache@0.1.0.0/cache.bend as Cache
Cache validity: expiry, negative results, invalidation, and generation-safe fetch completion. Source: https://github.com/paymog/bend-kit/tree/main/cache
2 imports
import Base import bend-kit-collections@0.1.2.0/omap.bend as OMap
Types
type Policy source · line 6 · raw
Data
How long a result stays fresh, in the units of the caller's clock.
Policy@ttl:Nat -> @negative_ttl:Nat -> Policy
type Found source · line 10 · raw
@-V:Data -> Data
What one fetch found upstream: a value at an upstream version, or nothing.
Found@-V:Data -> @version:Nat -> @value:V -> Found<V>
Missing@-V:Data -> Found<V>
type Entry source · line 15 · raw
@-V:Data -> Data
A cached result. It serves a read at now only while now < expires.
Hit@-V:Data -> @version:Nat -> @value:V -> @expires:Nat -> Entry<V>
Miss@-V:Data -> @expires:Nat -> Entry<V>
type Slot source · line 22 · raw
@-V:Data -> Data
The state of one key. Fetches take the generations floor, floor+1, ..., next-1. A completion lands only when floor <= its generation < next. It then raises floor past its generation, so no older fetch can land after it.
Slot@-V:Data -> @next:Nat -> @floor:Nat -> @entry:Maybe<&2, Entry<V>> -> Slot<V>
type Ticket source · line 27 · raw
Type
One fetch in flight: its key, its generation, and the clock when it started. It is affine, so it completes at most once.
Ticket@key:String -> @gen:Nat -> @at:Nat -> Ticket
type Cache source · line 30 · raw
@-V:Data -> Data
Cache@-V:Data -> @policy:Policy -> @slots:0xd2d968d969a26029a632a3347c989456/omap.OMap<String, Slot<V>> -> Cache<V>
Definitions
def Slot.new source · line 36 · raw
@-V:Data -> Slot<V>
def Entry.expires source · line 39 · raw
@-V:Data -> @e:Entry<V> -> Nat
def Entry.of source · line 47 · raw
@-V:Data -> @r:Found<V> -> @p:Policy -> @at:Nat -> Entry<V>
The entry for a result fetched at at. Its age counts from the fetch start.
def Slot.serve source · line 56 · raw
@-V:Data -> @fresh:Bool -> @e:Entry<V> -> Maybe<&2, Entry<V>>
def Slot.lookup source · line 63 · raw
@-V:Data -> @m:Maybe<&2, Entry<V>> -> @+now:Nat -> Maybe<&2, Entry<V>>
def Slot.read source · line 71 · raw
@-V:Data -> @s:Slot<V> -> @+now:Nat -> Maybe<&2, Entry<V>>
The fresh entry at now, or None when the caller must fetch.
def Slot.start source · line 76 · raw
@-V:Data -> @s:Slot<V> -> Pair(Nat, Slot<V>)
Takes the next generation for a new fetch.
def Slot.complete.if source · line 80 · raw
@-V:Data -> @ok:Bool -> @n:Nat -> @f:Nat -> @m:Maybe<&2, Entry<V>> -> @g:Nat -> @e:Entry<V> -> Slot<V>
def Slot.complete source · line 88 · raw
@-V:Data -> @p:Policy -> @s:Slot<V> -> @+g:Nat -> @at:Nat -> @r:Found<V> -> Slot<V>
Stores the result of fetch g, unless g is stale or was never issued.
def Slot.invalidate source · line 93 · raw
@-V:Data -> @s:Slot<V> -> Slot<V>
Drops the entry and voids every fetch issued so far.
def Slot.evict source · line 98 · raw
@-V:Data -> @s:Slot<V> -> Slot<V>
Drops the entry. The generations stay, so no fetch that was stale before is accepted after.
def key.cmp.fin source · line 105 · raw
@c:Cmp -> @rest:Cmp -> Cmp
def key.cmp source · line 115 · raw
@a:String -> @b:String -> Cmp
Keys in code-point order. String.order rebuilds both strings on every call.
def Cache.new source · line 126 · raw
@-V:Data -> @p:Policy -> Cache<V>
Templates
template Cache.slot source · line 129 · raw
@-V:Data -> @slots:0xd2d968d969a26029a632a3347c989456/omap.OMap<String, Slot<V>> -> @+key:String -> Slot<V>
template Cache.put source · line 132 · raw
@-V:Data -> @p:Policy -> @slots:0xd2d968d969a26029a632a3347c989456/omap.OMap<String, Slot<V>> -> @+key:String -> @+s:Slot<V> -> Cache<V>
template Cache.read source · line 136 · raw
@-V:Data -> @c:Cache<V> -> @+key:String -> @+now:Nat -> Maybe<&2, Entry<V>>
The fresh entry for key at now, or None when the caller must fetch.
template Cache.start.fin source · line 140 · raw
@-V:Data -> @p:Policy -> @slots:0xd2d968d969a26029a632a3347c989456/omap.OMap<String, Slot<V>> -> @+key:String -> @at:Nat -> @r:Pair(Nat, Slot<V>) -> Pair(Ticket, Cache<V>)
template Cache.start source · line 145 · raw
@-V:Data -> @c:Cache<V> -> @+key:String -> @at:Nat -> Pair(Ticket, Cache<V>)
Starts a fetch of key at clock at. Fetch upstream, then pass the ticket to complete.
template Cache.complete source · line 150 · raw
@-V:Data -> @c:Cache<V> -> @t:Ticket -> @r:Found<V> -> Cache<V>
Stores what the ticket's fetch found. A stale ticket changes nothing.
template Cache.invalidate source · line 156 · raw
@-V:Data -> @c:Cache<V> -> @+key:String -> Cache<V>
Drops key's entry and voids its fetches in flight.
template Cache.evict source · line 161 · raw
@-V:Data -> @c:Cache<V> -> @+key:String -> Cache<V>
Drops key's entry. Its generations stay, so stale fetches stay stale.