Skip to content

Instantly share code, notes, and snippets.

@stefl
Created June 9, 2017 18:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stefl/092921a4b8583fbf8a19b1fd284313b0 to your computer and use it in GitHub Desktop.
Save stefl/092921a4b8583fbf8a19b1fd284313b0 to your computer and use it in GitHub Desktop.
# encoding: utf-8
module Prismic
class Memcache
def initialize(max_size=100)
end
def set(key, value, expired_in = nil)
Rails.cache.write(key, value, :expires_in => expired_in = expired_in && Time.now.getutc.to_i + expired_in)
value
end
def []=(key, value)
set(key, value, nil)
end
def get(key)
Rails.cache.read(key)
end
alias :[] :get
def get_or_set(key, value = nil, expired_in = nil)
Rails.cache.fetch(key, :expires_in => expired_in = expired_in && Time.now.getutc.to_i + expired_in) { block_given? ? yield : value }
end
def delete(key)
Rails.cache.delete(key)
nil
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment