How can I cache the results returned by searchkick in rails using low level caching?

58 views Asked by At

How can I cache the results returned by searchkick in rails using low level caching? It seems the returned items object is unique on every search, thus busting the cache?

Here is some sample code I'm using.. in my controller

cache_key = ["results_controller", @store, @category, @search, @page]
@items = Rails.cache.fetch(cache_key, expires_in: 1.week) {Searchkick.search(@search...)}

I then have a

@sid = @items.search.id

down below to track searches.. I believe this search_id is unique per search, thus busting the cache.. how can I cherry pick the attributes returned in the .search method so as to preserve the caching?

This is for a multi-model search query.. hence using Searchkick.search() instead of YourModel.search()

0

There are 0 answers