-
Notifications
You must be signed in to change notification settings - Fork 202
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Recommended caching strategies? #168
Comments
hi @mgburns, import {createClient} from 'contentful'
const client = createClient({
space: '<space-id>',
accessToken: '<token>',
host: 'mycacheproxy.com'
}) the SDK will then make http request against your proxy. for e.g when requesting an entry the expected endpoint will be here is a list of all possible configs that you can pass to the client. |
From a design perspective I wouldn't cache calls to our CDN on your end, as you would need to implement all the things we're actually already doing for you, like availability, edge caching, etc. It's important to mention here what counts towards the limits and I'm citing the docs here:
So if you don't hit 78 unique uncached URIs a second, you're good to go. If you do, there might be better counter-measurements than caching it yourself. |
@Khaledgarbaya Thanks for the quick response! I was hoping I could mount it at a different base path, but that's a good workaround and I've confirmed it does work as intended. @zcei Good point re: CDN functionality that is sacrificed with this approach. That said, we're building a universal application wherein the initial fetch to Contentful always occurs server-side, and as such doesn't really benefit from the CDN anyways. I'm not as concerned about the rate limiting as I am about the plan limits as it impacts cost for our client (e.g. 250,000 API call per month, +$0.10 for 1,000 more). I had reached out to the Contentful support team as I noticed that most of my requests were coming back as
|
@zcei Good thought! That's a potential solution, but it would be a much heavier lift for us than a simple caching proxy with a short TTL. We would have to rewrite all application code interfacing with the Contentful SDK, and it also introduces additional points of failure (webhook sending, receiving, and the sync operation). Are you aware of any open source projects implementing this pattern? |
Nope, haven't had the use-case by now. To just ease the burden of burst requests, a cache would be most simple indeed. |
Thank you both for your responses! |
I'm working on a universal React application that requires multiple requests on page load and am investigating caching strategies to help performance and alleviate the pressure on our API request limit. I've seen #83 and know that this SDK does not handle caching out-of-the-box.
My initial thought was to create a caching proxy layer on our application server (similar to https://github.com/felixjung/contentful-proxy), but I can't figure out a way to make that work with this SDK as the baseURL is not exposed in a way that lets me modify the path.
For example, my proxy lives at
https://my-server.com/api/contentful/
, so a request tohttps://my-server.com/api/contentful/spaces/123
caches the response forhttps://cdn.contentful.com/spaces/123
.Has anyone else attempted something like this? Are their other approaches that others have had success with?
The text was updated successfully, but these errors were encountered: