Created
June 9, 2017 18:09
-
-
Save stefl/092921a4b8583fbf8a19b1fd284313b0 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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