[TYPO3-dev] Clear cache inline in typo3 extension

Stephan Schuler Stephan.Schuler at netlogix.de
Thu Jan 29 14:09:48 CET 2015


Hey there.

The actual command depends on what you're trying to do. But calling DataHandler::clear_cacheCmd() trough frontend isn't exactly a good idea. That one will check if the current BE user is allowed to clear the cache, which most likely isn't the case for regular FE users.

Better use the \TYPO3\CMS\Core\Cache\CacheManager.
Go for either CacheManager::flushCachesInGroupByTag(), CacheManager::flushCachesByTag() or CacheManager::flushCachesInGroup().

If you want to clear e.g. the page cache for page uid 42, just call CacheManager::flushCachesByTag('pageId_42').
That's what the BE does when you call DataHandler::clear_cacheCmd the right way, and that's what BE does when you just edit page 42 in TCEforms.

On top of that, you really should use proper tagging. There is no need to clear e.g. the cache of page uid 42 completely if page 42 is like "news details" and you just changed one single news. That would drop every single cached detail of every single news rendered, although it would be just enough to drop a single argument set, like "clear cache of page uid 42 having rendered news 1337, but not cache of page 42 having rendered any other news except 1337".

That would require two things:
1: Tag the news details page with "tx_news_domain_model_news_1337" during rendering.
2: Call CacheManager::flushCachesByTag('tx_news_domain_model_news_1337') when that news changes.
The later step is done by BE automatically as soon as you save a record.

Unfortunately the Extbase persistence doesn't call the CacheManager automatically during insert and update. So whenever a FE plugin changes a record, you need to call the "flushCachesByTag" by hand. But that shouldn't be much of a problem.

Using caches is an important thing because cached content is always delivered like magnitudes faster than uncached content is. But using caches based on proper and fine grained cache tags is nearly as important as musing caches at all because clearing lots of caches all day long could cause your cacheable page being delivered uncached most of the time.

Think about e.g. some news page showing "comments" feeds where like every second FE users add new comments. Now let your FE users rate on both, the news record and every single comment. This will cause your page record to be cleared literally once a second and makes your nice caching nearly useless if it's not based on proper tags.

Regards,


Stephan Schuler
Web-Entwickler | netlogix Media

Telefon: +49 (911) 539909 - 0
E-Mail: Stephan.Schuler at netlogix.de
Web: media.netlogix.de




netlogix GmbH & Co. KG
IT-Services | IT-Training | Media
Neuwieder Straße 10 | 90411 Nürnberg
Telefon: +49 (911) 539909 - 0 | Fax: +49 (911) 539909 - 99
E-Mail: info at netlogix.de | Web: http://www.netlogix.de

netlogix GmbH & Co. KG ist eingetragen am Amtsgericht Nürnberg (HRA 13338)
Persönlich haftende Gesellschafterin: netlogix Verwaltungs GmbH (HRB 20634)
Umsatzsteuer-Identifikationsnummer: DE 233472254
Geschäftsführer: Stefan Buchta, Matthias Schmidt



-----Ursprüngliche Nachricht-----
Von: typo3-dev-bounces at lists.typo3.org [mailto:typo3-dev-bounces at lists.typo3.org] Im Auftrag von Caspar Stuebs
Gesendet: Mittwoch, 14. Januar 2015 12:56
An: Dennis Dittrich; List for Core-/Extension development
Betreff: Re: [TYPO3-dev] Clear cache inline in typo3 extension

Hi Dennis,

I like to help you, but you have to be more specific what you like to do.

- Which cache and how much of the cache do you like to clear? Configuration Cache? Pages Cache? Only for one page, for a bound of pages, all pages?
- From which context you need to clear the cache? Backend, cli, other?

The cache clearing mechanism is located in class \TYPO3\CMS\Core\DataHandling\DataHandler line 6958ff

You may use the function clear_cacheCmd($cacheCmd) or registerRecordIdForPageCacheClearing($table, $uid) one of the hooks inside.

Kind Regards
Caspar

2015-01-14 10:59 GMT+01:00 Dennis Dittrich <dittrich at netspione.de>:

> Hello Developers,
>
> i search for a method to delete/clear the fontend cache of typo3 5.2
> cms after i insert some data in database.
> Greets from Germany,
> Dennis Dittrich
>
>
>
> _______________________________________________
> TYPO3-dev mailing list
> TYPO3-dev at lists.typo3.org
> http://lists.typo3.org/cgi-bin/mailman/listinfo/typo3-dev
>

--
--

Gosign media. GmbH | We web ideas.
Langenfelder Damm 67 Gewerbehof | 22525 Hamburg Telefon 040-609 40 79-0

Handelsregister AG HH HRB 112197 | Geschäftsführung Bert Gogolin Greenpeace energy: Gosign läuft mit ehrlichem Strom und Gas.
GLS Bank: Gosign wirtschaftet mit Gewissen.
_______________________________________________
TYPO3-dev mailing list
TYPO3-dev at lists.typo3.org
http://lists.typo3.org/cgi-bin/mailman/listinfo/typo3-dev


More information about the TYPO3-dev mailing list