Welcome, Guest. Register Now!
   
Mark Forums Read Mark Forums Read Mark Forums Read


Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 03-19-2008, 02:27 AM
Junior Member
 
Join Date: Mar 2008
Posts: 2
Default zend_cache question

I am new to Zend and am attempting to cache a large db query. If it's not cached, it works (in the sense that I can iterate through my Table_Rowset in my view). But, if it's cached, I always get the following (snipped):

__PHP_Incomplete_Class Object ( [__PHP_Incomplete_Class_Name] => Zend_Db_Table_Rowset..... "followed by all of the data I expect"

I'm creating my cache object in the preDispatch() function with the following code:
PHP Code:
require_once 'Zend/Cache.php';
        
$frontendOptions = array(
            
'lifetime' => 7200,
            
'automatic_serialization' => true
        
);
        
$cache_path Zend_Registry::get('cache_path');
        
$backendOptions = array(
            
'cache_dir' => $cache_path->temp_dir
        
);
        
$this->cache Zend_Cache::factory('Core''File'$frontendOptions$backendOptions); 
Then, I try to use it in my IndexAction(), like this:

PHP Code:
    function IndexAction() {
        
$this->view->title "View Agent";
        
$order $this->_request->get("order");
        if(!
$cached_agents $this->cache->load('agents_list_cached')) {
            
$agents = new Agent();
            if(isset(
$order) && $order == "lname" || $order == "fname" || $order == "email" || $order == "city" || $order == "state" || $order == "phone" )
                
$cached_agents $agents->fetchAll($agents->select()->where('status = ?''A')->order($order));
            else
                
$cached_agents $agents->fetchAll($agents->select()->where('status = ?''A')->order('lname'));
            
$this->cache->save($cached_agents'agents_list_cached');
            
$this->view->agents $this->cache->load('agents_list_cached');
        } else {
print_r($cached_agents);
//print_r($this->cache->load('agents_list_cached'));
die();
            
$this->view->agents $this->cache->load('agents_list_cached');
            
//die($cached_agents);
        
}
    } 
But as mentioned above, this is not returning the correct type of object???

Suggestions???

Thanks,
Darren
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 03-20-2008, 11:50 AM
Junior Member
 
Join Date: Mar 2008
Posts: 2
Default solved

I was finally able to resolve this by adding two loadClass statements above my cache loads. For example,

PHP Code:
    function IndexAction() {
        
$this->view->title "View Agent";
        
$order $this->_request->get("order");
// these two classes are required because I'm caching.  If I don't use
// caching, they somehow get magically loaded....
Zend_Loader::loadClass('Zend_Db_Table_Rowset');
Zend_Loader::loadClass('Zend_Db_Table_Row');
        
$this->view->cached_agents $this->cache->load('agents_list_cached');
        if(!
$this->view->cached_agents) {
            
$agents = new Agent();
            if(isset(
$order) && $order == "lname" || $order == "fname" || $order == "email" || $order == "city" || $order == "state" || $order == "phone" )
                
$this->view->cached_agents $agents->fetchAll($agents->select()->where('status = ?''A')->order($order));
            else
                
$this->view->cached_agents $agents->fetchAll($agents->select()->where('status = ?''A')->order('lname'));
            
$this->cache->save($this->view->cached_agents'agents_list_cached');
        }
    } 
This problem seems to relatively uncommon. I was only able to find two threads on google where this problem was addressed. I didn't really understand the solution to either thread. But, the thread at this link gave me enough to figure it out.
Nabble - Zend Framework - Zend_Cache, storing objects
I don't understand why the example in the Zend Framework documentation is not more clear on this.
Zend Framework: Documentation
BTW, I know that my logic is flawed. So, if you are here looking for an a solution to your own problem, don't let that throw you off. If I sort my table by any order other than id, the cached version doesn't match what I want. But, that wasn't my short term goal. I just wanted to get my cache working. That part is working. I'll work on the remaining logic next.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT. The time now is 03:51 AM.