Slacker News Slacker News logo featuring a lazy sloth with a folded newspaper hat
  • top
  • new
  • show
  • ask
  • jobs
Library
← Back to context

Comment by wood-porch

8 months ago

Doesn't that shift the problem to caching false then :D

1 comment

wood-porch

Reply

RangerScience  8 months ago

you can probably always just do something like:

  def no_items?
    !items.present?
  end
  
  def items
    # something lone
  end

  memoize :items, ttl: 60, max_size: 10`

just makes sure the expensive operation results in a truthy value, then add some sugar for the falsey value, done.

Slacker News

Product

  • API Reference
  • Hacker News RSS
  • Source on GitHub

Community

  • Support Ukraine
  • Equal Justice Initiative
  • GiveWell Charities