3

I've built a custom component, and I'm trying to make it a bit faster, and while I was rooting through model core files I saw that their getItems() uses a caching to reduce DB queries:

$store = $this->getStoreId();
if (isset($this->cache[$store]))
{
    return $this->cache[$store];
}

try
{
    // Load the list items and add the items to the internal cache.
    $this->cache[$store] = $this->_getList($this->_getListQuery(), $this->getStart(), $this->getState('list.limit'));
}

So I'm attempting to duplicate this for my component. Code is practically the same, but whenever I check isset($this->cache[$store]) it is always unset. I'm unsure if I'm having a problem fetching $this->cache[$store] or saving to it.

  • Have you checked the PHP error logs? – Lodder Aug 22 '17 at 13:25
  • Just poked around the log files and turned on Development mode for Error Reporting, still no messages. – Chaosxmk Aug 22 '17 at 15:47
  • Which version of Joomla? Which PHP version? Which cache handler? What's the cache time? – Lodder Aug 22 '17 at 16:10
  • This is all running on Joomla! 3.7.5 and PHP 5.6.30. The cache handler is set to File with a cache time of 15 minutes. – Chaosxmk Aug 22 '17 at 19:12
  • Print out the $store variable and see what it is getting set to or if it is getting set at all. – Terry Carter Aug 22 '17 at 23:50
2
+25

In your component controller, check the display function:

public function display($cachable = false, $urlparams = false)
{    
    //...

    parent::display($cachable, $safeurlparams);

    return $this;
}

Change it to:

parent::display(true, $safeurlparams);

And test again.

  • I tried forcing $cachable to true to no avail, but I did however see a spot where I might be able to investigate to help fix the problem. Will report back once I've had time to poke around and what not. – Chaosxmk Aug 23 '17 at 19:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.