Method: Innate::Cache::API#cache_delete

Defined in:
lib/innate/cache/api.rb

#cache_delete(key, *keys) ⇒ Object Array nil

Remove the corresponding key/value pair for each key passed. If removing is not an option it should set the corresponding value to nil.

If only one key was deleted, answer with the corresponding value. If multiple keys were deleted, answer with an Array containing the values.

NOTE: Due to differences in the underlying implementation in the

caches, some may not return the deleted value as it would mean
another lookup before deletion. This is the case for caches on
memcached or any database system.

Parameters:

  • key (Object)

    the key for the value to delete

  • keys (Object)

    any other keys to delete as well

Returns:

  • (Object Array nil)

Author:

  • manveru



63
64
65
66
67
68
69
70
71
# File 'lib/innate/cache/api.rb', line 63

def cache_delete(key, *keys)
  if keys.empty?
    if value = yield(key)
      value[:value]
    end
  else
    [key, *keys].map{|element| cache_delete(element) }
  end
end