gacache

Types

Actions are passed to the Cache to interact with its Store

pub type Action(key, value) {
  Set(key: key, value: value)
  Get(ret: process.Subject(Result(value, Error)), key: key)
  Clear(key: key)
  Keys(ret: process.Subject(List(key)))
  Reset
  Raw(ret: process.Subject(Store(key, value)))
  Merge(store: Store(key, value))
  Stop
}

Constructors

  • Set(key: key, value: value)
  • Get(ret: process.Subject(Result(value, Error)), key: key)
  • Clear(key: key)
  • Keys(ret: process.Subject(List(key)))
  • Reset
  • Raw(ret: process.Subject(Store(key, value)))
  • Merge(store: Store(key, value))
  • Stop
pub type Error {
  NotCached
  Timeout
}

Constructors

  • NotCached

    Provided when the Get Action is sent with a Key that has no corresponding Value

  • Timeout

    Provided when either a Get or Raw Action cannot be completed in 10 seconds

Functions

pub fn clear(cache: Subject(Action(a, b)), key: a) -> Nil

Removes the Value associated with the provided Key from the Store

pub fn get(
  cache: Subject(Action(a, b)),
  key: a,
) -> Result(b, Error)
pub fn keys(cache: Subject(Action(a, b))) -> List(a)

Returns all keys known by the Store

pub fn merge(
  cache: Subject(Action(a, b)),
  new_store: Dict(a, b),
) -> Nil

Merges the Store with the provided Store using dict:merge/2

pub fn raw(
  cache: Subject(Action(a, b)),
) -> Result(Dict(a, b), Error)

Returns the Store, avoid if possible

pub fn reset(cache: Subject(Action(a, b))) -> Nil

Clears the whole Store

pub fn set(cache: Subject(Action(a, b)), key: a, value: b) -> Nil

Updates the Store with key=value

pub fn start() -> Result(Subject(Action(a, b)), StartError)

Start the cache

pub fn stop(cache: Subject(Action(a, b))) -> Nil

Stops the cache

Search Document