菜单

How to enable Memcached cache in TYPO3 4.3

2010年12月7日 - typo3

Types of caches in TYPO3

There are three different caches in TYPO3 4.3:

  • cache_hash
    This cache saves data produced by some TYPO3 functions, mainly by substituteMarkerArrayCached. This cache can be very large, it is used only if page is not cached and it does not make sense to enable Memcached for this cache. Database or file will work best.
  • cache_pagesection
    This cache stores parsed TypoScript templates. It can be stored in Memcached but database is my personal preference for this cache.
  • cache_pages
    This cache stores pages. This is what needs to be as fast as possible. So Memcached will be the best candidate for this cache.

How to configure caches

By default caches use database to store data. However it can be changed. For example the following code in typo3conf/localconf.php will use different cache backends for different caches:

$TYPO3_CONF_VARS[‘SYS’][‘caching’][‘cacheBackendAssignments’] = array(
‘cache_hash’ => array(
‘backend’ => ‘t3lib_cache_backend_File‘,
‘options’ => array(
)
),
‘cache_pages’ => array(
‘backend’ => ‘t3lib_cache_backend_Memcached‘,
‘options’ => array(
‘servers’ => array(‘localhost:11211’),
)
),
‘cache_pagesection’ => array(
‘backend’ => ‘t3lib_cache_backend_Db‘,
‘options’ => array(
‘cacheTable’ => ‘cache_pagesection’,
)
)
);

Bold text shows you how different caches are configured. Here cache_hash uses file backend. If you symlink typo3temp/ or typo3temp/cache/ to the RAID1 partition, this cache will be very fast and will not produce any load on MySQL.

cache_pagesection uses database. Notice how we configure table name.

cache_pages uses Memcached. Configuration says that Memcached server is located on the localhost and accessible through port 11211 (default Memcached configuration). You can set up other Memcached instances and add them to the list separating instances by commas. Make sure you have no spaces anywhere. But localhost will work best because network delays will make Memcached useless.

Install Memcached

Memcached should be installed on the server. Internet has plenty of instructions about it, so I will not repeat them.

Configure Memcached in PHP

I do not pretend to be an expert in Memcached but I created a reasonable configuration for Memcached locally. This requires modifying php.ini. After changing default values Memcached requests became faster (I confirmed it by profiling with XDebug). Here is my settings:

memcache.allow_failover 1
memcache.chunk_size 32768
memcache.default_port 11211
memcache.hash_function fnv
memcache.hash_strategy consistent
memcache.max_failover_attempts 20

And of course you need to have Memcached PHP extension installed.

from: http://dmitry-dulepov.com/article/how-to-enable-memcached-cache-in-typo3-43.html

It should be noted that the config options where renamed (TYPO3 4.3 Alpha2);
You should always check your config against:
t3lib/config_default.php
Below example works fine for me with current TYPO3 SVN-Version:
hth regards georg

<pre>
$TYPO3_CONF_VARS[‘SYS’][‘caching’][‘cacheConfigurations’] = array (
‘cache_hash’ => array(
‘backend’ => ‘t3lib_cache_backend_MemcachedBackend’,
‘options’ => array(
‘servers’ => array(‘localhost:11211’),
)
),
‘cache_pages’ => array(
‘backend’ => ‘t3lib_cache_backend_MemcachedBackend’,
‘options’ => array(
‘servers’ => array(‘localhost:11211’),
)
),
‘cache_pagesection’ => array(
‘backend’ => ‘t3lib_cache_backend_MemcachedBackend’,
‘options’ => array(
‘servers’ => array(‘localhost:11211’),
)
),
);
</pre>

发表评论

电子邮件地址不会被公开。 必填项已用*标注