[TYPO3-dev] Data exchange between USER/USER_INT
Ernesto Baschny [cron IT]
ernst at cron-it.de
Tue Dec 4 20:49:25 CET 2007
Oliver Hader wrote: on 04.12.2007 20:23:
>>> This is one of the multi-optional problems of TYPO3. It's possible to do
>>> it in different ways, but the developer has to decide one. I'd like to
>>> have a general 'extension storage' that can handle data created by
>>> runtime and put it into cache. This function also has to be loaded and
>>> written automatically (like it's done in the $TSFE->config example),
>>> because otherwise each extension which requires this behaviour has to do
>>> its own caching again and again.
>>>
>>> What I try to explain is: We need some standards for such things.
>> I don't see that you are creating a standard, but just one more way to
>> cache data in TYPO3. And having a standard where extensions store more
>> and more stuff in TSFE which has to be loaded on each call doesn't look
>> like something that would scale to me.
> The intitial example was thought be just an _example_, nothing more. And
> all I wanted to know was if there was a better way to do this. Putting
> (maybe large) things to TSFE doesn't make sense, of course. Furthermore
> I didn't say that I'm creating a standard - but it would be nice to have
> some standards for common tasks (besides my special use case). And since
> caching is sometimes a mystical thing, I would be great to have also
> some kind of standard API for extension caching.
Ah ok, I thought that you didn't want to consider gethash / storeHash
because of some reason. I misunderstood!
>> storeHash and getHash are already there and you can use it. It might not
>> be the most well documented feature, and maybe there are missing
>> features with it (e.g. a too short "ident" field or no
>> "memory-caching"), so we might enhance it. But it works well and I have
>> used it for caching FE-rendering stuff in several applications.
> Great! Then I'm asking you to update and enhance the documentations on
> that and feed it with your knowledge concerning this topic. Thanks in
> advance! :)
Well, it is not very difficult, and this is the current "use case". The
API is described in t3lib_pageSelect::getHash() and
t3lib_pageSelect::storeHash(), refer to your preferred typo3-api-doc URL.
Now some example:
You have a method in some class that is able to calculate something very
fancy but takes lots of processing to do it on every hit, so you want
that to be cached. For example:
function getBlurbExpensiveOperation($id) {
// here comes the code that is expensive and will be cached
....
return $blurb;
}
So you make a wrapper around it, and start using that instead of the
"expensive" operation:
function getBlurb($id) {
$hash = md5('blurb'.$id);
$blurb = $GLOBALS['TSFE']->sys_page->getHash($hash);
if (!$blurb) {
// not found in cache, re-calculate
$blurb = $this->getBlurbExpensiveOperation($id);
}
$GLOBALS['TSFE']->sys_page->storeHash($hash, $blurb, 'blurb-'.$uid);
}
In this case I try to get it from cache, if it is not there, I just
calculate it again and at the end store it back in the cache table. I do
this even if it was already cached, because this will refresh the
timestamp which you might use to "expire" old cached entries.
The ident field ("blurb-$id") is just for "information", it is not used
anywhere. But makes it easy to find and identify your cached entries
when using phpMyAdmin. Might even be used to "clean" your own plugins cache.
Cheers,
Ernesto
More information about the TYPO3-dev
mailing list