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 996461
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T06:52:46+00:00 2026-05-16T06:52:46+00:00

I use Stacic Page Cache (with cache action helper) to cache most of the

  • 0

I use Stacic Page Cache (with cache action helper) to cache most of the pages of my App.
This is extremly fast, but not always suitable.

  • How do you cache pages with dynamic data? Eg. layout contains info specific to user.

One solution I considered is to load additional data via Ajax.
But in my case it would be better to cache parts of the pages (eg. list of entries or sidebar partial).

  • Is there any ZF recommended way to do it? Eg. cache the view only, not the layout or vice versa.

Cache action helper provides nice interface to cache all the actions. Any solution to cache the page content or partials or view helpers?

  • 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-16T06:52:47+00:00Added an answer on May 16, 2026 at 6:52 am

    What I’ve been doing lately is creating a service and then configuring that service with both a db connection and a cache object. Retrieving the data uses a kind of “lazy-loading cascade”, looking first in memory, then in cache, then to the db.

    For example, one of my apps is for a real-estate agency that operates in several – but not all – of the provinces in our country. We have a db-table of provinces, some of which are enabled for the front-end, and we need to render them in various places (say, as options in a select element). We do something like this (the legacy code-base on which I am working uses DAO objects for db access and PEAR’s Cache_Lite for caching, so the example is not strictly Zend Framework, but the principle applies equally):

    /**
     * A service for fetching provinces
     */
    class My_Service_Provinces
    {
        protected $_daoProvinces;
        protected $_provinces = array();
        protected $_cache;
    
    
        public function __construct($daoProvinces)
        {
            $this->setDaoProvinces($daoProvinces);
        }
    
        public function setDaoProvinces($daoProvinces)
        {
            $this->_daoProvinces = $daoProvinces;
            return $this;
        }
    
        public function getDaoProvinces()
        {
            return $this->_daoProvinces;
        }
    
        public function setCache($cache)
        {
            $this->_cache = $cache;
            return $this;
        }
    
        public function getCache()
        {
            if (null == $this->_cache){
                $this->_cache = new My_Cache_Provinces();
            }
            return $this->_cache;
        }
    
        public function getProvinces()
        {
            if (null == $this->_provinces){
                $cache = $this->getCache();
                $data = $cache->get();
                if (!$data){
                    $dao = $this->getDaoProvinces();
                    $rows = $dao->frontend();
                    $data = array();
                    while ($row = $rows->get_row()){
                        $data[$row['provinceId']] = $row;
                    }
                    $cache->save(serialize($data));
                } else {
                    $data = unserialize($data);
                }
                $this->_provinces = $data;
            }
            return $this->_provinces;
        }
    
        public function getProvince($provinceId)
        {
            $provinces = $this->getProvinces();
            return isset($provinces[$provinceId]) ? $provinces[$provinceId] : null;
        }
    }
    

    The cache object is pre-configured with whatever lifetime is appropriate. I give a long lifetime to seldom-changing data, shorter lifetimes to frequently-changing data. If I really need the change to the data to be immediately available to the app – say, the admin adds a new province – I instantiate the cache object and clear the cache on update.

    I’ve even added a factory to help instantiate the service so that calling code does not have to sweat the dependencies. Calling code – perhaps in a controller or even in a view or view-helper – looks something like:

    $service = My_Service_Factory::getService('provinces');
    $provinces = $service->getProvinces();
    

    Knowwhatimsayin’?

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

Sidebar

Related Questions

I'm trying to implement functionality to cache certain pages depending on the host. This
I have this very simple control below. And on the page that i use
I use System.Web.Services.WebMethodAttribute to make a public static method of an ASP.NET page callable
I need to explain myself why I do not use static methods/propertis. For example,
nginx is handling all static page requests, but from within my fastcgi application I
On this page , I would like to horizontally center the main #container div
In ASP.NET Webforms, I can use <%@ OutputCache Duration=3600 VaryByParam=none%> to cache a web
This should be an easy one to track down...but it isn't proving that way
I like to use static functions in C++ as a way to categorize them,
Possible Duplicate: When to Use Static Classes in C# Questions in the title..........i would

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.