Skip to content
This repository has been archived by the owner on Jun 13, 2019. It is now read-only.

Caching a response #3

Open
zizther opened this issue Nov 18, 2015 · 6 comments
Open

Caching a response #3

zizther opened this issue Nov 18, 2015 · 6 comments

Comments

@zizther
Copy link

zizther commented Nov 18, 2015

Hi.

This is a great plugin and works well.
I was wondering if it were possible somehow to cache a response?

Thanks

@wesrice
Copy link
Collaborator

wesrice commented Nov 18, 2015

@zizther That is a valid point. I had not thought about that yet, as I've been caching in an non-Craft application that consumes the api responses.

I think there are a few options on the table.

  1. Generating a hash based on query parameters and caching for X amount of minutes as defined in the config. There would need to be events that bust the cache.

  2. I think there is a larger structural issue within this application and this caching issue could be solved by addressing this problem. In short, this plugin creates PSR-7 compatible request object on each request and then ends up sending back a PSR-7 response object. It would be nice to be able to define custom middleware that can be executed between the two. This would allow for plugins that can extend the native functionality, allowing a cache specific plugin to be written to define caching in a very specific way.

I'm going to mull these options over and talk it over with my team. Your input is greatly appreciated too.

@zizther
Copy link
Author

zizther commented Nov 19, 2015

Thanks Wes.

At the moment I have the API being consumed separately and storing it in files being pushed to an S3.

Option 1 was something I was thinking about, but as you say there needs to be caching busting involved.

Option 2 does sound like what Craft have in mind, being they have opened up the caching to allow plugin devs to use other methods of caching (Redis, memcache, etc). I don't know if this plugin can fit in with how Craft has opened it self up to caching?

Thanks for the looking into this, be good to know what you and the team think of.

@wesrice
Copy link
Collaborator

wesrice commented Dec 14, 2015

@zizther We have decided to go with the middleware approach and will be restructuring things soon. We are going to implement RelayPHP and allow for a middleware queue to be defined in the plugin's config.

@zizther
Copy link
Author

zizther commented Dec 14, 2015

Sounds interesting. Is that approach because of how you need to use the plugin for projects?

Your probably aware that Craft will eventually have its own REST API (I don't think this is scheduled for Craft 3 anymore), but they are opening up Craft's caching to allow developers to create plugins which can extend it and use Redis or Memcache.

@wesrice
Copy link
Collaborator

wesrice commented Dec 15, 2015

The middleware approach is an architectural change that will give us (or anyone else) greater flexibility to implement caching or any other additional layer, such as logging, throttling, OAuth, etc.

We will utilize as much of the native cache drivers as possible that Craft might provide, but we'll have the flexibility to implement additional cache drivers if need be.

@zizther
Copy link
Author

zizther commented Dec 15, 2015

Thanks for the updates. Look forward to seeing the updates.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants