Class: ActiveCachedResource::CachingStrategies::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/active_cached_resource/caching_strategies/base.rb

Direct Known Subclasses

ActiveSupportCache, SQLCache

Instance Method Summary collapse

Instance Method Details

#clear(pattern) ⇒ Boolean

Clears the cache based on the given pattern.



44
45
46
# File 'lib/active_cached_resource/caching_strategies/base.rb', line 44

def clear(pattern)
  clear_raw(pattern)
end

#delete(key) ⇒ void

This method returns an undefined value.

Deletes the cached value associated with the given key.



35
36
37
# File 'lib/active_cached_resource/caching_strategies/base.rb', line 35

def delete(key)
  delete_raw(hash_key(key))
end

#read(key) ⇒ Object?

Reads the value associated with the given key from the cache.

Raises:

  • (ArgumentError)


9
10
11
12
13
# File 'lib/active_cached_resource/caching_strategies/base.rb', line 9

def read(key)
  raise ArgumentError, "key must be a String or Symbol" unless key.is_a?(String) || key.is_a?(Symbol)
  raw_value = read_raw(hash_key(key))
  raw_value && decompress(raw_value)
end

#write(key, value, options) ⇒ Boolean

Writes an object to the cache with the specified key and options.

Options Hash (options):

  • :expires_in (Integer)

    The expiration time in seconds for the cached object. (required)

Raises:

  • (ArgumentError)

    If the ‘:expires_in` option is missing.



25
26
27
28
29
# File 'lib/active_cached_resource/caching_strategies/base.rb', line 25

def write(key, value, options)
  raise ArgumentError, "`expires_in` option is required" unless options[:expires_in]

  write_raw(hash_key(key), compress(value), options)
end