Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Query Cache #59

Open
bounoable opened this issue Aug 4, 2022 · 1 comment
Open

Query Cache #59

bounoable opened this issue Aug 4, 2022 · 1 comment

Comments

@bounoable
Copy link
Contributor

bounoable commented Aug 4, 2022

Implement a flexible cache for event queries.

Features

  • Automatic cache key based on the query filters
  • Time-based and manual expiry
  • Optional cache storage

Examples

Basic usage

package example

import (
  "github.com/modernice/goes/event"
  "github.com/modernice/goes/event/query"
)

func example(store event.Store, q event.Query) {
  cache := query.NewCache(store)

  result, err := cache.Result(context.TODO(), q)
  // handle err

  if result.Cached {
    log.Println("cache returned cached result")
  } else {
    log.Println("cache executed query")
  }

  events, err := streams.Drain(context.TODO(), result.Events, result.Errs)
  // handle err

  // alternatively

  str, errs, err := cache.Run(context.TODO(), q)
  // handle err

  events, err := streams.Drain(context.TODO(), str, errs)
}
@bounoable
Copy link
Contributor Author

This would allow for an aggregate cache:

package example

func example(repo aggregate.Repository) {
  cached := repository.Cached(repo)

  var foo aggregate.Aggregate
  err := cached.Fetch(context.TODO(), foo)
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant