cheddargetter-client-php icon indicating copy to clipboard operation
cheddargetter-client-php copied to clipboard

Caching

Open benserrette opened this issue 13 years ago • 3 comments

Added caching. Caches getCustomer and getPlans. Uses Memcache, APC or Sessions depending on which is available.

benserrette avatar Aug 20 '12 13:08 benserrette

Hi Ben -- Thanks for this. First, I think you should take a look at the way the adapter pattern is used to abstract the http client library used as well as how globals are referenced. I'd like for the cache mechanism to use the adapter pattern. This way, it'd be trivial for someone to write their own adapter if they happen to use something other than the native memcache or APC or whatever. Check these out, for example:

https://github.com/benabus/cheddargetter-client-php/blob/master/Http/AdapterInterface.php

https://github.com/benabus/cheddargetter-client-php/blob/master/Http/NativeAdapter.php

So, a cache interface would have method like load, save, remove, etc. (those are cache-speak for get, set and delete).

Also, I'm afraid I jumped the gun a little. Since you worked on this I've implemented a CG cache on the server side. The client side should leverage this just like a GUI browser would, for example. CG is now honoring the If-Modified-Since and If-None-Match request headers for a few request types. The advantage here is that the client can make the request as usual, receive the cache headers, cache if instructed then subsequent requests receive a 304. It's all a bit complicated. If you'd like to continue working on this, let me know and we can sit down and get into some more detail.

marcguyer avatar Aug 28 '12 15:08 marcguyer

I must not understand the adapter pattern as well as I thought. Let me study up on this a bit more and I'll get back to you.


Ben Serrette Lead Developer Code Together LLC https://squadedit.com @squadedit

On Tue, Aug 28, 2012 at 11:38 AM, Marc Guyer [email protected]:

Hi Ben -- Thanks for this. First, I think you should take a look at the way the adapter pattern is used to abstract the http client library used as well as how globals are referenced. I'd like for the cache mechanism to use the adapter pattern. This way, it'd be trivial for someone to write their own adapter if they happen to use something other than the native memcache or APC or whatever. Check these out, for example:

https://github.com/benabus/cheddargetter-client-php/blob/master/Http/AdapterInterface.php

https://github.com/benabus/cheddargetter-client-php/blob/master/Http/NativeAdapter.php

So, a cache interface would have method like load, save, remove, etc. (those are cache-speak for get, set and delete).

Also, I'm afraid I jumped the gun a little. Since you worked on this I've implemented a CG cache on the server side. The client side should leverage this just like a GUI browser would, for example. CG is now honoring the If-Modified-Since and If-None-Match request headers for a few request types. The advantage here is that the client can make the request as usual, receive the cache headers, cache if instructed then subsequent requests receive a 304. It's all a bit complicated. If you'd like to continue working on this, let me know and we can sit down and get into some more detail.

— Reply to this email directly or view it on GitHubhttps://github.com/marcguyer/cheddargetter-client-php/pull/4#issuecomment-8095983.

benserrette avatar Aug 28 '12 17:08 benserrette

Okay, I've essentially translated it to use more of an adapter pattern, based on the other adapters/interfaces that I saw (Http, Client). I'm hoping this is more of what you were looking for. I haven't added in anything related to your sever-side caching.

Let me know if you think these updates are any better and if you would still like my help. It's been a learning experience for me.

benserrette avatar Aug 30 '12 15:08 benserrette