Skip to content
Discussion options

You must be logged in to vote

Wrap it in a Blink or Cache so it's not executed multiple times. https://statamic.dev/computed-values#performance

Collection::computed('news_articles', 'reactions', function ($article) {
  $key = 'article_reaction-'.$article->id();
  return Cache::rememberForever($key, function () { // or Blink::once()
    // ...
  });
});

You can invalidate it by listening for EntrySaved

Event::listen(function (EntrySaved $event) {
  Cache::forget('article_reaction-'.$event->entry->id());
});

If you're using Blink, nothing is actually cached since it's only for that request. You don't need to invalidate it.

Replies: 2 comments 2 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
2 replies
@sunscreem
Comment options

@sunscreem
Comment options

Answer selected by sunscreem
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants