Giter Club home page Giter Club logo

Comments (4)

sebbean avatar sebbean commented on August 10, 2024 1

maybe new ticket "enable actual caching" would help clarify for some people

from contentful_rails.

edtjones avatar edtjones commented on August 10, 2024

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.

maqen avatar maqen commented on August 10, 2024

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.

edtjones avatar edtjones commented on August 10, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.