Comments (4)
maybe new ticket "enable actual caching" would help clarify for some people
from contentful_rails.
Hi @maqen I'll improve the readme. In short, though, what you're doing should work ok. If @car
is a ContentfulModel object, it should respond to cache_key which means Rails views will cache OK.
You can prove this out by doing the following in a console session:
c = Car.first #should be an instance of Car, which inherits from ContentfulModel::Base
c.cache_key #should return a string, representing the cache key for this object
Hope that helps?
from contentful_rails.
But how can I get Car.first
without hitting the contentful api? Don't see the point in caching like this then?
from contentful_rails.
Hi @maqen you're right - this doesn't obviate the need for an API hit to get a collection of Car
objects, but it would stop you having to make a call to get more child data if you have a parent/child relationship in Contentful.
The only thing which is cached (by default) is the timestamp - so the logic goes like this:
- Get collection of things (does require API hit)
- cache view partial based on cache key (which includes the cached timestamp component)
- if the timestamp doesn't exist, you need to render the whole partial
- if the timestamp does exist, render the view you've already cached
This doesn't mean your site will freewheel if contentful is down, and there is still a dependency on contentful for the data. But the view rendering is fast.
It's not a panacea. The proper way to do this would be to receive the webhook data and cache an entire model object. Unfortunately that requires some refactoring of the Contentful gem to create an object which looks identical, from either the API response or the webhook callback data. See contentful/contentful.rb#55 - if you fancy attacking that I know @pxlpnk and I would be grateful :-)
Hope that helps?
from contentful_rails.
Related Issues (20)
- Concern with `eager_load!` HOT 14
- Subclassing MarkdownRenderer HOT 5
- Missing attr_writer for attributes with nil values HOT 3
- #delete_matched not supported by all ActiveSupport cache types HOT 2
- alias_method_chain call in timestamps.rb causes deprecation warning HOT 4
- this thing work? HOT 10
- Rails 5 support? HOT 1
- enable caching support HOT 7
- Can't load gem without ActiveRecord HOT 6
- Webhooks Rails 5 HOT 6
- Webhooks fail in Rails 5.1 HOT 2
- Content types caching blowing up VCR on CI HOT 1
- Release webhooks fix? HOT 1
- Load error HOT 5
- Support Contentful Model 1.0 HOT 2
- OOM errors in Docker HOT 9
- Webhook Engine does not provide the /debug route as expected HOT 1
- How do you perform the russian nesting doll cache?
- "Only Redis glob strings are supported: " on unpublish when using redis as cache store
- Eager load in a to_prepare block
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from contentful_rails.