What problem does it solve?
Golem agent methods that only read state still go through the full invocation queue and agent loading, wasting resources and blocking behind slow writes. This Skill shows how to mark Scala agent methods as read-only so Golem caches their results, bypasses the queue on cache hits, and traps forbidden side effects at runtime.
Core Features & Use Cases
- Read-Only Annotation: Apply the
@readOnly annotation to Scala agent methods to guarantee a side-effect-free contract, with writes to persistent state, outgoing HTTP, and RPC calls trapping with a ReadOnlyViolation error.
- Configurable Cache Policies: Choose between
until-write (default), ttl(<duration>), and no-cache policies via the annotation's cache argument.
- Automatic Per-Principal Caching: Methods receiving a
Principal parameter are automatically cached per principal, with HTTP responses switching to Cache-Control: private and Vary: Authorization.
- Use Case: Expose a
getCount() query on a counter agent as an HTTP GET endpoint that returns instantly from cache with proper Cache-Control and ETag headers, even while a slow write is being processed.
Quick Start
Add the @readOnly annotation to my Scala agent's getCount method so its result is cached until the next write.