module IndexedCache

Public Instance Methods

cache!() click to toggle source
# File lib/moysklad/resources/indexed_cache.rb, line 2
def cache!
  all.count
end

Private Instance Methods

cache() click to toggle source
# File lib/moysklad/resources/indexed_cache.rb, line 16
def cache
  @cache ||= {}
  @cache[cache_key] ||= { index: nil, list: nil}
end
cache_fetch() { || ... } click to toggle source
# File lib/moysklad/resources/indexed_cache.rb, line 8
def cache_fetch
  return cache[:list] if cache[:list]
  cache[:list] = yield
  cache[:index] = prepare_index cache[:list]

  cache[:list]
end
cache_index(index) click to toggle source
# File lib/moysklad/resources/indexed_cache.rb, line 25
def cache_index(index)
  cache[:index] = index
end
cache_key() click to toggle source
# File lib/moysklad/resources/indexed_cache.rb, line 29
def cache_key
  if __getobj__.respond_to? :cache_key
    __getobj__.send :cache_key
  else
    :default
  end
end
cached_index() click to toggle source
# File lib/moysklad/resources/indexed_cache.rb, line 21
def cached_index
  cache[:index]
end