modernice / goes

goes is an event-sourcing framework for Go.
https://goes.modernice.dev
Apache License 2.0
134 stars 12 forks source link

Cached Repository #126

Open bounoable opened 1 year ago

bounoable commented 1 year ago

Provide an Aggregate Repository with cache features.

package example

func example(repo aggregate.Repository) { // or aggregate.TypedRepository[...]
  cached := repository.NewCache(repo)

  // Only runs once
  q := query.New(...)
  cached.Query(context.TODO(), q)
  cached.Query(context.TODO(), q)

  // Only runs once
  id := uuid.New()
  cached.Fetch(context.TODO(), id)
  cached.Fetch(context.TODO(), id)

  // Clear cache
  cached.Reset()
}
bounoable commented 1 year ago

Fetch() cache implemented in 4b51c724c21f3992b55e61898b0967258a885762