ruby on rails - Cache warming with RABL for JSON templates -
OK, this post is a bit of a word before reaching the actual question, so the compressed version basically deals with caching RABL templates Rabl.render vs. API calls, cache-keys are not the same in the generated cache.
Kashmir, now wind-up ..
When I have Rab Should I expect to match cash-keys when using render? To improve the reuse of the underlying objects in a Rail API API server archive on Heroku, I have done very well with RABL using Russian doll caching. However, I still go with the archive cache, when the user is generated for the first time on request, this is a burden on experience (like 1 + second API call).
... API / v1 / activities / 26600: Calling for the same object ... api / v1 / activities (after the call above) I get the desired cash hit: RABL provides a way to provide a template directly from the code () which definitely looks like the correct approach. This is the use case. Therefore, I intend to use an RABL engine To call (for example - a user login event). So for the above API example, I call the following Rail Console and expect cash hits. Unexpectedly, I could not find a cache hit, but It is clear that cache-keys are not the same as the previous hash sign is missing. I am not sure why the cash-key will be different in this case. I'm not leaving a way to heat the cache for RABL templates. UPDATE The template hash that turns the hash into the previous cache key. Although it tells me the source of that hash, it is still unclear why its use directly from calling For example: / Code> I think it is too heavy of a solution, and still feels that there is a solution with Raval :: render.
read the cache: rabl / activity / 26600 -20140423170223588554000 // hash / d30440d18014c72014a05319af0626f7 cash generated: rabl / activity / 26600-20140423170223588554000 // hash / d30440d18014c72014a05319af0626f7 cache type: rabl / activity / 26600-20140423170223588554000 // hash / d30440d18014c72014a05319af0626f7
Reading cache: rabl / activity / 26600-20140423170223588554000 // hash / d30440d18014c72014a05319af0626f7 cache fetch_hit: rabl / activity / 26600-20140423170223588554000 // hash / d304 40d18014c72014a05319af0626f7 This works great! The next step is to avoid having any API call spending to generate cash before.
That's why I'm pursuing cash-warming techniques to generate collections before the user can reach them. A suggestion is using the wget API as a way to kill straight (see). But this adds a load on the Hacaku Web Dynis, so I want to do background cache warming through sidekick workers.
irb (main): 002: 0> @activity = Activity.find (26600) irb (main): 003: 0> Rabl.render (@activity, 'api / v2 / activity / show_no_root' ,: view_path = & gt; 'app / view' ,: format = & gt ;: json) Read the cache: rabl / activity / 26600-20140423170223588554000 // Hash cache generated: rabl / activity / 26600-20140423170223588554000 // hash cache type: rabl / activity / 26600-20140423170223588554000 // hash
Cache digest for API / v1 / activities / _show. Rabl: d30440d18014c72014a05319af0626f7
Rabl :: renderer does not happen. Due to the missing template digest hash in the cache, I was not able to use Rabl ::: key. Although by creating a sidekick worker below, I can heat the cache by calling AP as a background process, which works well.
class CacheWarmApi includes Sidekiq :: Worker sidekiq_options: queue = & gt; : Warmers def performance (url_helper, args, params = {}, method = 'get') if method == 'get' session = ActionDispatch :: integration :: session.new (Rails.application) session.get (session.send For example:
CacheWarmApi.perform_async (: api_v2_expensiveapi_url, args_array, params_hash)
Comments
Post a Comment