Class: JsonApiResource::CacheProcessor::CompressedCacheProcessor
- Defined in:
- lib/json_api_resource/cache_processor/compressed_cache_processor.rb
Class Method Summary collapse
Class Method Details
.fetch(client, action, *args) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/json_api_resource/cache_processor/compressed_cache_processor.rb', line 28 def fetch(client, action, *args) key = cache_key(client, action, *args) set = cache.fetch key raise KeyError.new("#{key} not found") if set.blank? # set can be an array of blobs or an array of ids set.map! do |item| # if the results are ids if item.is_a? Integer # grab the actual object from cache key = item_cache_key(client, action, item) cache.fetch key # if they are not ids else # they have to be the full objects. return them item end end JsonApiClient::ResultSet.new(Array(set)) end |
.write(result, client, action, *args) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/json_api_resource/cache_processor/compressed_cache_processor.rb', line 9 def write(result, client, action, *args) result_set = Array(result) key = cache_key(client, action, *args) # result set has ids and we can break the set down into an array of ids and the objects if splitable?(result_set) write_ids(key, result_set) write_objects(client, action, result_set) else cache.write key, result_set end result end |