bend-kit-cache Releases (3): 0.3.0.0 0x1afe27789226a57428f7ceb2621e112e indexed https://jend.leeeet.dev/files.txt?path=bend-kit-cache@0.3.0.0 0.2.0.0 0x802468e43b166a885d45fe62ddb7935d unindexed https://jend.leeeet.dev/files.txt?path=bend-kit-cache@0.2.0.0 0.1.0.0 0x9898b5ac55a7416e5d4c033f525f5bd8 unindexed https://jend.leeeet.dev/files.txt?path=bend-kit-cache@0.1.0.0 Definitions (26): Cache.Policy (https://jend.leeeet.dev/definition.txt?path=bend-kit-cache@0.3.0.0/cache.bend&name=Policy) # How long a result stays fresh, in the units of the caller's clock. type Policy is Data: Policy{ttl: Nat, negative_ttl: Nat} Cache.Found (https://jend.leeeet.dev/definition.txt?path=bend-kit-cache@0.3.0.0/cache.bend&name=Found) # What one fetch found upstream: a value at an upstream version, or nothing. type Found<-V: Data> is Data: Found{version: Nat, value: V} Missing{} Cache.Entry (https://jend.leeeet.dev/definition.txt?path=bend-kit-cache@0.3.0.0/cache.bend&name=Entry) # A cached result. It serves a read at `now` only while now < expires. type Entry<-V: Data> is Data: Hit{version: Nat, value: V, expires: Nat} Miss{expires: Nat} Cache.Slot (https://jend.leeeet.dev/definition.txt?path=bend-kit-cache@0.3.0.0/cache.bend&name=Slot) # 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. type Slot<-V: Data> is Data: Slot{next: Nat, floor: Nat, entry: Maybe<&2, Entry>} Cache.Ticket (https://jend.leeeet.dev/definition.txt?path=bend-kit-cache@0.3.0.0/cache.bend&name=Ticket) # One fetch in flight: its key, its generation, and the clock when it started. # It is affine, so it completes at most once. type Ticket is Type: Ticket{key: String, gen: Nat, at: Nat} Cache.Cache (https://jend.leeeet.dev/definition.txt?path=bend-kit-cache@0.3.0.0/cache.bend&name=Cache) type Cache<-V: Data> is Data: Cache{policy: Policy, slots: OMap.OMap>} Cache.Slot.new (https://jend.leeeet.dev/definition.txt?path=bend-kit-cache@0.3.0.0/cache.bend&name=Slot.new) def Slot.new(-V: Data) -> Slot: Cache.Entry.expires (https://jend.leeeet.dev/definition.txt?path=bend-kit-cache@0.3.0.0/cache.bend&name=Entry.expires) def Entry.expires(-V: Data, e: Entry) -> Nat: Cache.Entry.of (https://jend.leeeet.dev/definition.txt?path=bend-kit-cache@0.3.0.0/cache.bend&name=Entry.of) # The entry for a result fetched at `at`. Its age counts from the fetch start. def Entry.of(-V: Data, r: Found, p: Policy, at: Nat) -> Entry: Cache.Slot.serve (https://jend.leeeet.dev/definition.txt?path=bend-kit-cache@0.3.0.0/cache.bend&name=Slot.serve) def Slot.serve(-V: Data, fresh: Bool, e: Entry) -> Maybe<&2, Entry>: Cache.Slot.lookup (https://jend.leeeet.dev/definition.txt?path=bend-kit-cache@0.3.0.0/cache.bend&name=Slot.lookup) def Slot.lookup(-V: Data, m: Maybe<&2, Entry>, +now: Nat) -> Maybe<&2, Entry>: Cache.Slot.read (https://jend.leeeet.dev/definition.txt?path=bend-kit-cache@0.3.0.0/cache.bend&name=Slot.read) # The fresh entry at `now`, or None when the caller must fetch. def Slot.read(-V: Data, s: Slot, +now: Nat) -> Maybe<&2, Entry>: Cache.Slot.start (https://jend.leeeet.dev/definition.txt?path=bend-kit-cache@0.3.0.0/cache.bend&name=Slot.start) # Takes the next generation for a new fetch. def Slot.start(-V: Data, s: Slot) -> Nat & Slot: Cache.Slot.complete.if (https://jend.leeeet.dev/definition.txt?path=bend-kit-cache@0.3.0.0/cache.bend&name=Slot.complete.if) def Slot.complete.if(-V: Data, ok: Bool, n: Nat, f: Nat, m: Maybe<&2, Entry>, g: Nat, e: Entry) -> Slot: Cache.Slot.complete (https://jend.leeeet.dev/definition.txt?path=bend-kit-cache@0.3.0.0/cache.bend&name=Slot.complete) # Stores the result of fetch g, unless g is stale or was never issued. def Slot.complete(-V: Data, p: Policy, s: Slot, +g: Nat, at: Nat, r: Found) -> Slot: Cache.Slot.invalidate (https://jend.leeeet.dev/definition.txt?path=bend-kit-cache@0.3.0.0/cache.bend&name=Slot.invalidate) # Drops the entry and voids every fetch issued so far. def Slot.invalidate(-V: Data, s: Slot) -> Slot: Cache.Slot.evict (https://jend.leeeet.dev/definition.txt?path=bend-kit-cache@0.3.0.0/cache.bend&name=Slot.evict) # Drops the entry. The generations stay, so no fetch that was stale before is accepted after. def Slot.evict(-V: Data, s: Slot) -> Slot: Cache.Cache.new (https://jend.leeeet.dev/definition.txt?path=bend-kit-cache@0.3.0.0/cache.bend&name=Cache.new) def Cache.new(-V: Data, p: Policy) -> Cache: Cache.Cache.slot (https://jend.leeeet.dev/definition.txt?path=bend-kit-cache@0.3.0.0/cache.bend&name=Cache.slot) def Cache.slot(~V: Data, slots: OMap.OMap>, +key: String) -> Slot: Cache.Cache.put (https://jend.leeeet.dev/definition.txt?path=bend-kit-cache@0.3.0.0/cache.bend&name=Cache.put) def Cache.put(~V: Data, p: Policy, slots: OMap.OMap>, +key: String, +s: Slot) -> Cache: Cache.Cache.read (https://jend.leeeet.dev/definition.txt?path=bend-kit-cache@0.3.0.0/cache.bend&name=Cache.read) # The fresh entry for key at `now`, or None when the caller must fetch. def Cache.read(~V: Data, c: Cache, +key: String, +now: Nat) -> Maybe<&2, Entry>: Cache.Cache.start.fin (https://jend.leeeet.dev/definition.txt?path=bend-kit-cache@0.3.0.0/cache.bend&name=Cache.start.fin) def Cache.start.fin(~V: Data, p: Policy, slots: OMap.OMap>, +key: String, at: Nat, r: Nat & Slot) -> Ticket & Cache: Cache.Cache.start (https://jend.leeeet.dev/definition.txt?path=bend-kit-cache@0.3.0.0/cache.bend&name=Cache.start) # Starts a fetch of key at clock `at`. Fetch upstream, then pass the ticket to complete. def Cache.start(~V: Data, c: Cache, +key: String, at: Nat) -> Ticket & Cache: Cache.Cache.complete (https://jend.leeeet.dev/definition.txt?path=bend-kit-cache@0.3.0.0/cache.bend&name=Cache.complete) # Stores what the ticket's fetch found. A stale ticket changes nothing. def Cache.complete(~V: Data, c: Cache, t: Ticket, r: Found) -> Cache: Cache.Cache.invalidate (https://jend.leeeet.dev/definition.txt?path=bend-kit-cache@0.3.0.0/cache.bend&name=Cache.invalidate) # Drops key's entry and voids its fetches in flight. def Cache.invalidate(~V: Data, c: Cache, +key: String) -> Cache: Cache.Cache.evict (https://jend.leeeet.dev/definition.txt?path=bend-kit-cache@0.3.0.0/cache.bend&name=Cache.evict) # Drops key's entry. Its generations stay, so stale fetches stay stale. def Cache.evict(~V: Data, c: Cache, +key: String) -> Cache: