Get Adobe Flash playerPlugin by wpburn.com wordpress themes

Posts Tagged ‘New in 4.3’

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:

// If cache is not already defined, define it
if (!is_array($TYPO3_CONF_VARS['SYS']['caching']
   ['cacheConfigurations']['my_extension'])) {
   $TYPO3_CONF_VARS['SYS']['caching']
      ['cacheConfigurations']['my_extension'] = array(
      'backend' => 't3lib_cache_backend_DbBackend',
      'options' => array(
         'cacheTable' => 'tx_myextension_cache',
         'tagsTable' => 'tx_myextension_cache_tags',
      )
   );
}

We use the database cache as the default. So we need to define the cache tables:

CREATE TABLE tx_myextension_cache (
   id int(11) NOT NULL auto_increment,
   identifier varchar(128) NOT NULL DEFAULT '',
   crdate int(11) unsigned NOT NULL DEFAULT '0',
   content mediumtext,
   lifetime int(11) unsigned NOT NULL DEFAULT '0',
   PRIMARY KEY (id),
   KEY cache_id (`identifier`)
);
CREATE TABLE tx_myextension_cache_tags (
   id int(11) NOT NULL auto_increment,
   identifier varchar(128) NOT NULL DEFAULT '',
   tag varchar(128) NOT NULL DEFAULT '',
   PRIMARY KEY (id),
   KEY cache_id (`identifier`),
   KEY cache_tag (`tag`)
);

Of course, any installation can overwrite the default definition by writing the definition in localconf.php:

$TYPO3_CONF_VARS['SYS']['caching']['cacheConfigurations']
   ['my_extension'] = array(
   'backend' => 't3lib_cache_backend_MemcachedBackend',
   'options' => array(
      'servers' => array('127.0.0.1:11211'),
   )
);

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.
Now in your extension you need to create and initialize the cache object:

if (TYPO3_UseCachingFramework) {
   // Create the cache
   try {
      $GLOBALS['typo3CacheFactory']->create(
         'my_extension',
         't3lib_cache_frontend_VariableFrontend',
         $GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']['my_extension']['backend'],
         $GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']['my_extension']['options']
      );
   } catch(t3lib_cache_exception_DuplicateIdentifier $e) {
      // do nothing, the cache already exists
   }
   // Initialize the cache
   try {
      $this->cache = $GLOBALS['typo3CacheManager']->getCache(
         'my_extension'
      );
   } catch(t3lib_cache_exception_NoSuchCache $e) {
      // Unable to load
   }
}

$this->cache will now hold the cache for your extension. You can now check if the cache has a certain ID:
$this->cache->has($id);
If it does, retrieve it:
$this->cache->get($id);
If not, then generate the content and store it:
$this->cache->set($id, $content, $tags, $lifetime);

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.

No Cache reason
December 2nd, 2009

Now when calling $TSFE->set_no_cache(), a reason can be provided and logged, making it easier to find why cache was disabled on a page.

Ex:
$TSFE->set_no_cache(‘Reached an unstable condition in extension xyz’);

More info:
Fix #11669: Provide a reason for why $TSFE->set_no_cache() has been triggered
http://bugs.typo3.org/view.php?id=11669

doNotLoadInFE
December 1st, 2009

New key in EM_CONF array, ‘doNotLoadInFE’ can be set to “1” for extensions that are only used in backend and have no front end components. This speeds up the frontend generation process, since extensions not doing anything in the FE will not be loaded on FE calls.

More info:
RFC #11474: Store separate extlist for the frontend
http://bugs.typo3.org/view.php?id=11474

One of the major features in TYPO3 4.3 is the advanced frontend editing. Although its not part of the official distribution, it is available as an extension, and adds amazing functionality to your TYPO3 driven site. But did you know that you can edit any other record in the frontend using feeditadvanced functionality? Here is some simple TypoScript code that allows you to edit tt_news records from the frontend:

plugin.tt_news.displayList.title_stdWrap.editPanel = 1
plugin.tt_news.displayList.title_stdWrap.editPanel {
editPanel = 1
allow = edit,hide,delete
line = 5
label = %s
onlyCurrentPid = 0
previewBorder = 4
edit.displayRecord = 1
}

Here is what you will see in the frontend, next to each tt_news title marker:

feedit_ttnews_1

And if you click edit, you will get a standard form allowing you to modify the record:

feedit_ttnews

Generally, any record that has stdWrap properties can be wrapped in this code to enable FE editing.

FE session data lifetime
November 30th, 2009

New setting stored in $GLOBALS['TYPO3_CONF_VARS']['FE']['sessionDataLifetime'] defines the lifetime of frontend session data in seconds. The setting can be modified in the Install tool.

More info:
FYI24 Feature #11508: Integrate possibility to define lifetime of frontend session data
http://bugs.typo3.org/view.php?id=11508
FYI24: Feature #11510: Store timestamp of last modification of session data to frontend user object
http://bugs.typo3.org/view.php?id=11510