-- Brett Scott <[EMAIL PROTECTED]> wrote
(on Wednesday, 26 November 2008, 12:14 PM -0000):
> I'm trying to work out the best way to implement caching in my application.  
> I've based my cache setup on Matthew's PasteBin application http://github.com/
> weierophinney/pastebin/tree/master (which is a great ZF example).
>  
> What I'd like to do is cache ajax calls from my Dojo FilteringSelect widget. 
> I'm not sure whether I should use Zend_Cache_Frontend_Page,  or
> Zend_Cache_Frontend_Output or simply Zend_Cache_Core and the best way to
> implement different types of caching in the same application (still set it up
> in the bootstrap?).
>  
> In the code below, a form element "payment_method_id" uses Dojo to call 
> "/data/
> payments/supplier_id/123456" (controller: data, action: payments, supplier_id=
> 123456) to obtain a list of payment methods based on "supplier_id".

You have a few ways to accomplish this. First, if you're using the MVC
to serve the XHR request for your FilteringSelect data, I wouldn't
really recommend Zend_Cache_Frontend_Page or Output. Instead, I'd
suggest using Zend_Cache_Core to cache the generated data and return it.

Second, there's nothing that says that you need to use the MVC to serve
the XHR request. If you look at recent revisions of the pastebin app,
I've actually moved all of these to a separate area under the public/
tree:

    public/
        api/
            v1/
                xmlrpc
                jsonrpc
                content/
                    ...

I setup rewrite rules that intercept calls to /api/v1/content/*.* and,
if the file is not found, generate the content from a script in the
api/v1/ directory. That script utilizes the Initializer plugin to
setup the DB and view, and then, after rendering the response,
caches it to a file under the content/ tree. This allows the content
to be primarily static for XHR calls -- which gives optimal
performance. Similarly, I cache the JSON-RPC server's SMD file so it
does not need to be generated each request.

Of course, this really only works for data that is relatively static --
but similar ideas could be applied to dynamic data. The approach
basically allows you to separate XHR concerns from your MVC layer by
building targetted, mini controller scripts that utilize the same
environment bootstrapping as your MVC application.

-- 
Matthew Weier O'Phinney
Software Architect       | [EMAIL PROTECTED]
Zend Framework           | http://framework.zend.com/

Reply via email to