Skip to content

Instantly share code, notes, and snippets.

@tsmango
Created June 25, 2009 16:47
Show Gist options
  • Save tsmango/135972 to your computer and use it in GitHub Desktop.
Save tsmango/135972 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