Project

General

Profile

Actions

Bug #28482

closed

t3lib_cache_backend_MemcachedBackend

Added by Raphaël Riel almost 13 years ago. Updated almost 11 years ago.

Status:
Rejected
Priority:
Should have
Assignee:
-
Category:
Caching
Target version:
-
Start date:
2011-07-26
Due date:
% Done:

0%

Estimated time:
TYPO3 Version:
4.6
PHP Version:
5.3
Tags:
Complexity:
easy
Is Regression:
Sprint Focus:

Description

Current interface t3lib_cache_backend_Backend exposes an has($entryIdentifier) function which return boolean-true if an item with given key is present in cache. This helper function is largely used among extensions and code that uses caching framework.

To implement this has() function, t3lib_cache_backend_MemcachedBackend currently does a "get() !=== FALSE" to return the result.
Upon a positive has(), 99% of the time, a get() with the exact same key will be issued.
This lead to two successive get call to memcache backend with the exact same key.

In my custom rewrite of the memcache backend, I keep the has() result in memory, and check back for it in every get() call.

Please see attached tx_libeomemcache_handler_LibeoMemcachedBackendBase class.


Files

libeo_memcache_custom.tar.gz (5.48 KB) libeo_memcache_custom.tar.gz Raphaël Riel, 2011-07-26 20:32
Actions #1

Updated by Steffen Gebert almost 13 years ago

  • TYPO3 Version changed from 4.5 to 4.6
  • Complexity changed from no-brainer to easy

I would say that it depends on the size of the caching data.

Can't be the following code in extensions

if has() then get()

be replaced with
 if get() !== FALSE 

unless you expect a boolean value from the caching data.

Actions #2

Updated by Raphaël Riel almost 13 years ago

None of my own extensions and project-specific code uses the has() function.
Unfortunately, there a lot of code spread around in Typo3 and 3rd party extensions that seems to use the has() function of the caching framework.
When I introduced the has()-buffer, I've seen the number of calls to memcached drop by about 30% on fully-cached pages.

Actions #3

Updated by Christian Kuhn almost 13 years ago

  • Category changed from Performance to Caching
  • Status changed from New to Rejected
  • Target version set to 4.6.0-beta1

has() is included in the backend and frontend interface and must not be removed or cached internally.

There are reasons why has() can be usefully: For example has() is used in phpCapableBackend before requireOnce().

Core itself does not use has() if it does not have to, because get() returns NULL if there is no entry. Maybe we could adapt the documentation at http://wiki.typo3.org/Caching_framework a bit to warn about this method.

So, I'll close this v4 issue now because it is out of scope. If you really want to get rid of has() (which I doubt), this change must go to FLOW3 anyway and would be backported after that.

Actions #4

Updated by Christian Kuhn almost 13 years ago

I've added some documentation for extension developers about has() to the wiki page. Feel free to improve it (at bottom of the page).

Actions #5

Updated by Raphaël Riel almost 13 years ago

Thanks for the documentation addition.

Unfortunately, I disagree with the point has() is not used widely.

Take a look at Tx_Extbase_Object_Container_Container->getClassInfo()
This function, for my project is called over 2500 times.

Just take a look at the "if" parts:

private function getClassInfo($className) {
    if (!$this->cache->has($className) || !is_object($this->cache->get($className))) {
        $this->cache->set($className, $this->classInfoFactory->buildClassInfoFromClassName($className));
    }
    return $this->cache->get($className);
}

Only for the "if", we get 3x more calls to cache (memcached for my project).
That's 3 calls, including the return's get(), instead of the one required.

When I implemented the has()-buffer, I managed to save A LOT of calls to memcached... and that was not only from the above function...

Seriously, if the Extbase team is using this function... I guess other are too...

And, on similar note, I just noticed the t3lib_cache_backend_DbBackend->has() is doing a COUNT on the DB's tables.
Most extensions that uses caching framework are pre-configured to use the Db-Backend?
That's two call to the db for a hit in the cache!
At least, it was for Extbase on my project...

Actions #6

Updated by Christian Kuhn almost 13 years ago

The above method is obviously unclever and should be optimized ... would you like to create a issue and patch for that in the mvc list and maybe push it to gerrit right away?

At first glance something like that should do:
$myObject = $cache->get()
if (!is_object($myObject)) {
$myObject = $doMagic();
$cache->set($myObject, ...);
}
return $myObject;

Actions #7

Updated by Raphaël Riel almost 13 years ago

I'll do.
This was the first "->has(" search result my IDE gave me back... there is still a lot around.. so, my point on the presence/implementation of the has() method still applies ;)

Actions #8

Updated by Ernesto Baschny almost 11 years ago

  • Target version deleted (4.6.0-beta1)
Actions

Also available in: Atom PDF