Hi Guys,
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
<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".
Thanks in advance :)
Brett.
==============================
Bootstrap.php
public function initCache()
{
$config = $this->config->cache;
$this->cache = $this->_getCache($config);
Zend_Registry::set('cache', $this->cache);
return $this;
}
protected function _getCache(Zend_Config $config)
{
$cache = Zend_Cache::factory(
$config->frontendName,
$config->backendName,
$config->frontendOptions->toArray(),
$config->backendOptions->toArray()
);
return $cache;
}
==============================
Config.ini
cache.backendName = "Sqlite"
cache.frontendName = "Core"
cache.frontendOptions.caching = false
cache.frontendOptions.lifetime = 900
cache.frontendOptions.automatic_serialization = true
cache.frontendOptions.automatic_cleaning_factor = 20
cache.backendOptions.cache_db_complete_path = APPLICATION_PATH
"/../data/cache/cache-dev.db"
cache.backendOptions.automatic_vacuum_factor = 20
==============================
Step1.php
class My_Form_Step1 extends My_Form
{
// ......
public function init()
{
// ......
$this->addElement(
'FilteringSelect',
'payment_method_id',
array(
'label' => 'Payment Method',
'storeId' => 'payment_method_id_store',
'storeType' => 'dojo.data.ItemFileReadStore',
'storeParams' => array(
'url' => $this->baseUrl() .
'/data/payments/supplier_id/123456',
),
'dijitParams' => array(
'searchAttr' => 'payment_method_title',
),
)
);
}
}
==============================
DataController.php
class DataController extends Zend_Controller_Action
{
public function init()
{
// Stop standard view output (template/layout/views)
$layout = Zend_Layout::getMvcInstance();
if ($layout instanceof Zend_Layout) {
$layout->disableLayout();
}
}
public function paymentsAction()
{
// ...... {{$matches is populated based on $supplier_id}}
$data = new Zend_Dojo_Data('payment_method_id', $matches);
echo $data->toJson();
}
}
==============================