Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5992541
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T23:32:47+00:00 2026-05-22T23:32:47+00:00

Zend_Cache can be configured to cache several types of output, including the results of

  • 0
Zend_Cache can be configured to cache several types of output, including 
the results of function calls, the results of object and static method calls, 
entire pages, and configuration data.

Given this controller and related views how would you go with caching?From what some of you suggested here (see @marcin) I understood that clearing the whole cache for just a single comment or a post-update would be too much.How should I go for them to be cached separately?

Basically I have a blog page where I’m loading all of the posts with relative users comments.

-Index controller (home-page):

class IndexController extends Zend_Controller_Action
{
  public function indexAction()
 {
  //Post is a db_table model
  $post_manager=new Post();
  $allPosts=$post_manager->getAllPosts();
  $this->view->posts=$allPosts;
 }

}

-index.phtml:

echo $this->partialLoop('_posts.phtml',$this->posts);

-_posts.phtml:

echo $this->object->title;
echo $this->object->text;
echo $this->partialLoop('_comments.phtml',$this->object->getComments());

-_comments.phtml:

echo $this->object->text;

Please post practical examples

thanks again

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T23:32:48+00:00Added an answer on May 22, 2026 at 11:32 pm

    Sorry I did not replay earlier. Quickly, I’ll would like to present one way of catching this for your consideration. For simplicity, I’ll just concentrate on caching your outputs using Output frontend.

    In you application.ini you can setup your catching as follows:

    resources.cachemanager.myviewcache.frontend.name = Output
    resources.cachemanager.myviewcache.frontend.customFrontendNaming = false
    resources.cachemanager.myviewcache.frontend.options.lifetime = 7200
    resources.cachemanager.myviewcache.frontend.options.caching = true
    resources.cachemanager.myviewcache.frontend.options.automatic_serialization = true
    resources.cachemanager.myviewcache.backend.name = Apc
    

    Note, that I use Apc as a backend. You may use file backend if you don’t have or don’t want Apc.

    With this, I would cache your posts and comments separately. For example, in _posts.phtml you could do something similar to the following:

    // first cache an output related to the body of your post with key being associated
    // with your post.
    if (!($this->viewCache()->start('post_' . (string) $this->object->post_id))) {
      echo $this->object->title;
      echo $this->object->text;
    }
    
    // now I cache an output of a comments associated with a give post
    if (!($this->viewCache()->start('post_comments_' . (string) $this->object->post_id))) {
      echo $this->partialLoop('_comments.phtml',$this->object->getComments());
    }
    

    In this example, viewCache() view helper is as follows:

    class My_View_Helper_ViewCache extends Zend_View_Helper_Abstract {
    
        /**
         *
         * @return Zend_Cache_Frontend_Output 
         */
        public function viewCache() {
            return Zend_Registry::get('outputCache');
        }    
    }
    

    Whereas I set outputCache into registry in the Bootstrap.php:

    protected function _initPutChachesIntoRegistry() {
        $this->bootstrap('cachemanager');
        $cacheManager = $this->getResource('cachemanager');
    
        Zend_Registry::set('outputCache', $cacheManager->getCache('myviewcache'));
    }
    

    Notice that caches are associated with keys which in turn relate to a given post and its comments. With this, when you get a new comment, you just reset a cache related to the given post. For example, in an action, you can remove comment cache for a post with $post_id=5 as follows:

    $this->view->viewCache()->remove('post_comments_' . $post_id);
    

    Hope that this will help you or at least give you some ideas how to make it.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Zend_Cache can be configured to cache several types of output, including the results of
I am attempting to use Zend_Cache_Frontend_Function to cache some of my own function calls.
I'm looking for solution for a in memory script cache, using Zend_Cache and zend
I'm using Zend_Cache_Core with Zend_Cache_Backend_File to cache results of queries executed for a model
I think I'm getting crazy, I'm trying to implement Zend_Cache to cache my database
How can i do the followin tasks public function addToCache($id,$items) { // in zend
i installed php op code cache. php -v produces correct output, showing eaccelerator. but
Is it possible to have two different cache instances for Zend_Cache ? For instance,
Warning: imagejpeg() [function.imagejpeg]: Unable to open '/home/SITENAME/public_html/files/cache/052f225905c1618003df0c5088aec7a9.jpg' for writing: Permission denied in /home/SITENAME/public_html/concrete/helpers/image.php on
I have some issues saving identifiers for cache objects in Zend_Cache . The Zend_Cache

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.