of: that is faster than other methods of getting that value and generally takes fewer resources 5 Wednesday, June 12, 13 fewer resources = less money, less time, less computing resources, less programming
@foo_bars = $cache["#{user.id}:foo_bars"] ||= user.foo_bars # busting v1 user.foo_bars.create(options) $cache["#{user.id}:foo_bars"] = nil # busting v2 $bust_it_at = 30.seconds.from_now if Time.now > $bust_it_at $bust_it_at = 30.seconds.from_now $cache = nil end 8 Wednesday, June 12, 13 This is great for instances where being slightly out-of-date is okay. For example, configuration settings that don’t change often, but do change live. Time-based checks. db- backed classes. in-process is fast. really, really fast.
tmp else tmp = user.foo_bars $redis.hset("cache", "#{user.id}:foo_bars", tmp) tmp end # busting user.foo_bars.create(options) $redis.hdel("cache", "#{user.id}:foo_bars") # Also $redis.get("cache:#{user.id}:foo_bars") 9 Wednesday, June 12, 13 This is totally fine if you don’t have memcache available and you do have redis
load on your dbs Really High?™ * Is my cache sharded in such a way that busting it will spread out increased load instead of causing hotspots? * Does redis have enough RAM? * Is my cache in the cloud located in a place that is slower over the network than running the queries would be? * Namespace yo’ shit. 13 Wednesday, June 12, 13