Error codes · Caches, keys and invalidation

PW5106

write_not_invalidated

The program must hold to this: a command invalidates what it writes: each cached reader of the data it changes, by name or through an event the reader listens for.

A program the compiler refuses with it

Refused: PW5106
module feed.stale

import context.{ current_session }
import capability.{ Session, SessionId }

opaque type InteractionId = String

type Post = Post { id: String, text: String }

type FeedError =
    | Unavailable

fn latest() -> List<Post> !{ database.read<Post> }
    host "feed:data/posts#latest"

fn publish(s: Session<SessionId>, text: String) -> Result<Post, FeedError> !{ database.write<Post> }
    host "feed:data/posts#publish"

public query Latest() -> List<Post>
    freshness 0.seconds
    cache     shared
{
    latest()
}

command post(text: String) -> Result<Post, FeedError>
    idempotent_by InteractionId
{
    publish(current_session(), text)
}

From Commands, in Data on the server. A test holds the guide's examples to the compiler.

The decisions behind it

0101

Reading the diagnostic

pw check prints the code in brackets, [PW5106], with the sentence above and the place in your program. Errors and diagnostics explains how to read one, and every code is listed with its rule.