
|
|
![]() Archive for January, 2010
Caching in extensions January 9th, 2010 TYPO3 4.3 features a new caching framework, which has been backported from FLOW3. The framework (should one choose to use it – more on that later) allows placement of default TYPO3 caches in DB tables, files, memcached, APC, or any other backend that can be created by implementing a PHP interface. But even more – TYPO3 extensions can easily leverage this framework to cache their output, configuration, or anything else they need to cache. Furthermore, the choice of backend is left up to the individual installations. Some may decide to use DB tables, others files, yet some others will go with an in-memory caching system, like memcached, or APC. Choice of storage would be completely transparent to the extension, which will simply use the framework regardless of the backend. Given all the caches TYPO3 offers, why would you want your own cache? Reasons vary. If your extension is a USER_INT object (which is not cached), but it queries the database, or external resources, you should use caching in your extension. Should the extension be used on a high traffic page, you don’t want it to become the point of contention. In this simple guide, I’ll cover some basics of enabling caching in your extensions. I’ll assume you’re running TYPO3 of at least version 4.3.0, and your extension lists this as a dependency. If it doesn’t, make sure to surround all code using the caching framework with checks for TYPO3 version (use t3lib_div::compat_version() function), and test on all supported TYPO3 versions. First you need to define the cache. Add this to the ext_localconf.php:
We use the database cache as the default. So we need to define the cache tables:
Of course, any installation can overwrite the default definition by writing the definition in localconf.php:
Since the ext_localconf.php in our extension is included after localconf.php, the extension needs to check that the caching definition is not already defined.
$this->cache will now hold the cache for your extension. You can now check if the cache has a certain ID: See the interface for more operations you can perform on the cache. The greatest thing about the caching framework is the fact that the specific caching backend is completely transparent to you – and each installation can use whatever method they deem appropriate, without any changes to your extension.
Visit Moscow January 7th, 2010 Got this ad in Facebook today: Huh? “Like to Travel?” – damn right. “Visit Moscow” – you got my interest. “We have jobs everywhere” – awesome! Wait, what’s that note about mafia? Mafia Wars? Is that where the jobs are? Is Russian mafia recruiting me through Facebook? |