Skip to content

Instantly share code, notes, and snippets.

@colin
Forked from tsmango/gist:135972
Created August 10, 2009 07:10
Show Gist options
  • Select an option

  • Save colin/165061 to your computer and use it in GitHub Desktop.

Select an option

Save colin/165061 to your computer and use it in GitHub Desktop.
# app/models/util/cache.rb
class Util::Cache
def self.increment(key, amount = 1)
if (value = Rails.cache.read(key)).nil?
Rails.cache.write(key, (value = amount))
else
Rails.cache.write(key, (value = value + amount))
end
return value
end
def self.decrement(key, amount = 1)
if (value = Rails.cache.read(key)).nil?
value = 0
else
Rails.cache.write(key, (value = value - amount))
end
return value
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment