watermarkchurch / wcc-contentful

An alternative to Contentful's contentful.rb ruby client, contentful_model, and contentful_rails gems all in one.
MIT License
2 stars 1 forks source link

Collection Cache Versioning #179

Open gburgett opened 5 years ago

gburgett commented 5 years ago

Currently the result of a Page.find_all is a lazy enumerable. If we rework this to be more of a "Relation" type object, we could concievably add cache keys to it.

pages = Pages.find_all
Rails.cache.fetch(pages.cache_key, version: pages.cache_version) { pages.to_a }

This would work by executing a query to the CDN to take the top 1 entry ordered by updatedAt descending. That updatedAt would then become the cache_version. documentation here: https://www.contentful.com/developers/docs/references/content-delivery-api/#/reference/search-parameters/order

This could also be a good solution to the problem of find_by caching: #18

jpowell commented 5 years ago

What does rails do when you provide a collection to the fresh_when method? We should take a cue from them on this topic.