Module: Kiosk::Cacheable::Connection

Defined in:
lib/kiosk/cacheable/connection.rb

Instance Method Summary collapse

Instance Method Details

#cache_expire_by_path(path) ⇒ Object



17
18
19
# File 'lib/kiosk/cacheable/connection.rb', line 17

def cache_expire_by_path(path)
  cache(:delete, cache_key(path))
end

#cache_expire_by_pattern(pattern) ⇒ Object



21
22
23
24
25
# File 'lib/kiosk/cacheable/connection.rb', line 21

def cache_expire_by_pattern(pattern)
  key_base = cache_key("")
  key = pattern.is_a?(Regexp) ? /^#{key_base}#{pattern}/ : "#{key_base}#{pattern}"
  cache(:delete_matched, key)
end

#cache_expiry=(expiry) ⇒ Object

Sets a value or block used to determine the expiry of written cache entries. If a block is given, its first argument will be the object that is about to be written.



7
8
9
# File 'lib/kiosk/cacheable/connection.rb', line 7

def cache_expiry=(expiry)
  @cache_expiry = expiry.is_a?(Proc) ? expiry : Proc.new { |r| expiry }
end

#cache_expiry_of(resource) ⇒ Object

Returns the expiry in seconds for the given resource.



13
14
15
# File 'lib/kiosk/cacheable/connection.rb', line 13

def cache_expiry_of(resource)
  @cache_expiry && @cache_expiry.call(resource)
end

#cache_key_matcherObject

Returns the type of key matcher supported by the cache store. Note that the type returned here may not be accurate for cache stores that don’t support matchers at all. For those cases, you should still expect NotImplemented exceptions to be thrown when calling cache_expire_by_pattern.



33
34
35
36
37
38
39
# File 'lib/kiosk/cacheable/connection.rb', line 33

def cache_key_matcher
  if defined?(ActiveSupport::Cache::RedisStore) && Rails.cache.is_a?(ActiveSupport::Cache::RedisStore)
    :glob
  else
    :regexp
  end
end

#delete(*arguments) ⇒ Object

:nodoc:



45
46
47
# File 'lib/kiosk/cacheable/connection.rb', line 45

def delete(*arguments) #:nodoc:
  cache_expire(arguments.first) { super }
end

#get(*arguments) ⇒ Object

:nodoc:



41
42
43
# File 'lib/kiosk/cacheable/connection.rb', line 41

def get(*arguments) #:nodoc:
  cache_read_write(arguments.first) { super }
end

#head(*arguments) ⇒ Object

:nodoc:



57
58
59
# File 'lib/kiosk/cacheable/connection.rb', line 57

def head(*arguments) #:nodoc:
  cache_read_write(arguments.first) { super }
end

#post(*arguments) ⇒ Object

:nodoc:



53
54
55
# File 'lib/kiosk/cacheable/connection.rb', line 53

def post(*arguments) #:nodoc:
  cache_expire(arguments.first) { super }
end

#put(*arguments) ⇒ Object

:nodoc:



49
50
51
# File 'lib/kiosk/cacheable/connection.rb', line 49

def put(*arguments) #:nodoc:
  cache_expire(arguments.first) { super }
end