Clearing the cache of a single instance of a page (single view) instead of the whole page

View: New views
11 Messages — Rating Filter:   Alert me  

Clearing the cache of a single instance of a page (single view) instead of the whole page

by Steffen Müller-4 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi.

If you have a classic single view page where a number of items are
displayed by using GETvars, there is no chance to clear the cache for a
single item, but only the whole page (e.g. using TCEmain->clear_cacheCmd).

A popular example is tt_news single view, e.g. the page
 http://www.example.com/?id=3&tx_ttnews[tt_news]=234
shows news article with uid=234.
tt_news docs suggests to use TCEMAIN.clearCacheCmd=3 to clear page cache
when an article has changed.
But that clears all instances of page 3:
 http://www.example.com/?id=3&tx_ttnews[tt_news]=1
 http://www.example.com/?id=3&tx_ttnews[tt_news]=2
 http://www.example.com/?id=3&tx_ttnews[tt_news]=...

Common clear cache functions seem to be too fuzzy to handle that. Now if
you have a website with many news articles, you might run into
performance problems.

I wonder if the caching framework gives us now some more control to
clear single view items from cache? If so, could you please point me to
the right direction?


--
cheers,
Steffen

TYPO3 Blog: http://www.t3node.com/
Blubber on Twitter: http://twitter.com/t3node
_______________________________________________
TYPO3-dev mailing list
TYPO3-dev@...
http://lists.netfielders.de/cgi-bin/mailman/listinfo/typo3-dev

Re: Clearing the cache of a single instance of a page (single view) instead of the whole page

by Rupert Germann :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

hi Steffen,

Steffen Müller schrieb:

> If you have a classic single view page where a number of items are
> displayed by using GETvars, there is no chance to clear the cache for a
> single item, but only the whole page (e.g. using TCEmain->clear_cacheCmd).
>
> A popular example is tt_news single view, e.g. the page
>  http://www.example.com/?id=3&tx_ttnews[tt_news]=234
> shows news article with uid=234.
> tt_news docs suggests to use TCEMAIN.clearCacheCmd=3 to clear page cache
> when an article has changed.
> But that clears all instances of page 3:
>  http://www.example.com/?id=3&tx_ttnews[tt_news]=1
>  http://www.example.com/?id=3&tx_ttnews[tt_news]=2
>  http://www.example.com/?id=3&tx_ttnews[tt_news]=...
>
> Common clear cache functions seem to be too fuzzy to handle that. Now if
> you have a website with many news articles, you might run into
> performance problems.
>
> I wonder if the caching framework gives us now some more control to
> clear single view items from cache? If so, could you please point me to
> the right direction?

have a look at the extensions
http://typo3.org/extensions/repository/view/ttnewscache/current/
http://typo3.org/extensions/repository/view/ttnewscache_clearlike/current/

also "COA_GO" might be helpful here
http://typo3.org/extensions/repository/view/coago/current/

greets
rupert
_______________________________________________
TYPO3-dev mailing list
TYPO3-dev@...
http://lists.netfielders.de/cgi-bin/mailman/listinfo/typo3-dev

Re: Clearing the cache of a single instance of a page (single view) instead of the whole page

by Steffen Müller-4 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hu Rupert,

thanks for the links.

On 15.10.2009 08:20 Rupert Germann wrote:
>
> have a look at the extensions
> http://typo3.org/extensions/repository/view/ttnewscache/current/
> http://typo3.org/extensions/repository/view/ttnewscache_clearlike/current/
>

I already tested it, but didn't like the approach to use SQL LIKE to
search for ids in HTML.

> also "COA_GO" might be helpful here
> http://typo3.org/extensions/repository/view/coago/current/
>

Thanks for this link to a very impressing extension.
But unfortunately this does not answer my question. Although this
extension would help to speed up building the page cache, cache items
still get deleted unnecessarily.

--
cheers,
Steffen

TYPO3 Blog: http://www.t3node.com/
Blubber on Twitter: http://twitter.com/t3node
_______________________________________________
TYPO3-dev mailing list
TYPO3-dev@...
http://lists.netfielders.de/cgi-bin/mailman/listinfo/typo3-dev

Re: Clearing the cache of a single instance of a page (single view) instead of the whole page

by Ernesto Baschny [cron IT] :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Steffen Müller schrieb:

> Hu Rupert,
>
> thanks for the links.
>
> On 15.10.2009 08:20 Rupert Germann wrote:
>> have a look at the extensions
>> http://typo3.org/extensions/repository/view/ttnewscache/current/
>> http://typo3.org/extensions/repository/view/ttnewscache_clearlike/current/
>>
>
> I already tested it, but didn't like the approach to use SQL LIKE to
> search for ids in HTML.
>
>> also "COA_GO" might be helpful here
>> http://typo3.org/extensions/repository/view/coago/current/
>>
>
> Thanks for this link to a very impressing extension.
> But unfortunately this does not answer my question. Although this
> extension would help to speed up building the page cache, cache items
> still get deleted unnecessarily.

This is still not an "answer", but some vision for the future:

in the new caching framework (starting with 4.3), tt_news could "tag"
his single views with certain key e.g. (tt_news:<uid>) and then hook
into the processdatamap of TCEmain to delete these cache entries when a
tt_news record is modified.

Without the caching framework, the "reg1" is the only way to somehow
identify cache entries. tt_news could store a 32-bit "hash" for its
single views and then also would be able to find them in the cache
afterwards.

Cheers,
Ernesto
_______________________________________________
TYPO3-dev mailing list
TYPO3-dev@...
http://lists.netfielders.de/cgi-bin/mailman/listinfo/typo3-dev

Re: Clearing the cache of a single instance of a page (single view) instead of the whole page

by Martin Kutschker-7 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Ernesto Baschny [cron IT] schrieb:
>
> in the new caching framework (starting with 4.3), tt_news could "tag"
> his single views with certain key e.g. (tt_news:<uid>) and then hook
> into the processdatamap of TCEmain to delete these cache entries when a
> tt_news record is modified.

The irony is that Rupi has worked to disable the caching framework by the default. So how is that
going to work when it's not active?

Masi
_______________________________________________
TYPO3-dev mailing list
TYPO3-dev@...
http://lists.netfielders.de/cgi-bin/mailman/listinfo/typo3-dev

Re: Clearing the cache of a single instance of a page (single view) instead of the whole page

by Rupert Germann :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Ernesto Baschny [cron IT] schrieb:
> Without the caching framework, the "reg1" is the only way to somehow
> identify cache entries. tt_news could store a 32-bit "hash" for its
> single views and then also would be able to find them in the cache
> afterwards.

reg1 is defined and handled as integer. to use it for other values it's
needed to change this at several places in the core. but then you could
also add your own field to the cache_pages table.

greets
rupert
_______________________________________________
TYPO3-dev mailing list
TYPO3-dev@...
http://lists.netfielders.de/cgi-bin/mailman/listinfo/typo3-dev

Re: Clearing the cache of a single instance of a page (single view) instead of the whole page

by JoH asenau :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

>> in the new caching framework (starting with 4.3), tt_news could "tag"
>> his single views with certain key e.g. (tt_news:<uid>) and then hook
>> into the processdatamap of TCEmain to delete these cache entries
>> when a tt_news record is modified.
>
> The irony is that Rupi has worked to disable the caching framework by
> the default. So how is that going to work when it's not active?

No big deal - since the tagging _and_ the hook should only be used after
checking if the caching framework is active or not.

Cheers

Joey

--
Wenn man keine Ahnung hat: Einfach mal Fresse halten!
(If you have no clues: simply shut your gob sometimes!)
Dieter Nuhr, German comedian
Xing: http://contact.cybercraft.de
Twitter: http://twitter.com/bunnyfield
TYPO3 cookbook (2nd edition): http://www.typo3experts.com


_______________________________________________
TYPO3-dev mailing list
TYPO3-dev@...
http://lists.netfielders.de/cgi-bin/mailman/listinfo/typo3-dev

Re: Clearing the cache of a single instance of a page (single view) instead of the whole page

by Steffen Müller-4 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi.

Thank you all for your input.

On 15.10.2009 11:42 Ernesto Baschny [cron IT] wrote:
> in the new caching framework (starting with 4.3), tt_news could "tag"
> his single views with certain key e.g. (tt_news:<uid>)

Do you have an example how tagging is done in the CF?
Are there some docs on the CF API? (beside phpdoc comments)

--
cheers,
Steffen

TYPO3 Blog: http://www.t3node.com/
Blubber on Twitter: http://twitter.com/t3node
_______________________________________________
TYPO3-dev mailing list
TYPO3-dev@...
http://lists.netfielders.de/cgi-bin/mailman/listinfo/typo3-dev

Re: Clearing the cache of a single instance of a page (single view) instead of the whole page

by Steffen Gebert :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Am 15.10.2009, 17:20 Uhr, schrieb Steffen Müller <typo3@...>:

> Hi.
>
> Thank you all for your input.
>
> On 15.10.2009 11:42 Ernesto Baschny [cron IT] wrote:
>> in the new caching framework (starting with 4.3), tt_news could "tag"
>> his single views with certain key e.g. (tt_news:<uid>)
>
> Do you have an example how tagging is done in the CF?
> Are there some docs on the CF API? (beside phpdoc comments)
>

This would be really interesting. I found out, how to get out sth. by a  
tag, but not how to store it using a tag.

Steffen
_______________________________________________
TYPO3-dev mailing list
TYPO3-dev@...
http://lists.netfielders.de/cgi-bin/mailman/listinfo/typo3-dev

Re: Clearing the cache of a single instance of a page (single view) instead of the whole page

by Steffen Müller-4 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi.

On 15.10.2009 17:24 Steffen Gebert wrote:
>
> This would be really interesting. I found out, how to get out sth. by a
> tag, but not how to store it using a tag.
>

For general use have a look at the cache frontend interface:
http://flow3.typo3.org/fileadmin/API/FLOW3/F3/FLOW3/Cache/Frontend/interface-FrontendInterface.html

set(string $entryIdentifier, mixed $data, array $tags=array(), integer
$lifetime=NULL)

$tags array is used to add tags to the cache entry.

You can find an example in t3lib_TStemplate->start() where set() is
using two tags:
array(
  'pageId_' . intval($GLOBALS['TSFE']->id),
  'mpvarHash_' . $mpvarHash
)

--
cheers,
Steffen

TYPO3 Blog: http://www.t3node.com/
Blubber on Twitter: http://twitter.com/t3node
_______________________________________________
TYPO3-dev mailing list
TYPO3-dev@...
http://lists.netfielders.de/cgi-bin/mailman/listinfo/typo3-dev

Re: Clearing the cache of a single instance of a page (single view) instead of the whole page

by Steffen Müller-4 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi.

On 15.10.2009 11:42 Ernesto Baschny [cron IT] wrote:
>
> in the new caching framework (starting with 4.3), tt_news could "tag"
> his single views with certain key e.g. (tt_news:<uid>) and then hook
> into the processdatamap of TCEmain to delete these cache entries when a
> tt_news record is modified.
>

I just read through the classes t3lib_TCEmain and tslib_fe and the
caching framework interface. This is the result of my exploration:

1) When using the caching framework, tslib_fe also supports reg1. The
reg1 value (integer) is used as a tag of the cache entry.

For example this can be used by
$GLOBALS['TSFE']->page_cache_reg1 = $this->piVars['tt_news']; // Example
GETvar: &tx_ttnews[tt_news]=123

Without caching framework:
field reg1=123 in table cache_pages

With caching framework:
cache entry has tag: reg1_123

This preserves backward compatibility.


2) When using the caching framework, tslib_fe allows to add tags to
$this->pageCacheTags by using $this->addCacheTags(array $tags)

That means one can use
$GLOBALS['TSFE']->addCacheTags(array('tx_ttnews_' .
$this->piVars['tt_news']); // Example GETvar: &tx_ttnews[tt_news]=123

The result is an additional tag in the cache entry: tx_ttnews_123


3) The t3lib_TCEmain API does not (yet) support clearing cache entries
by tag. But it could be enhanced with a function clear_cache_by_tags()

public function clear_cache_by_tags(array $tags=array()) {
  if (TYPO3_UseCachingFramework) {
    $pageCache = $GLOBALS['typo3CacheManager']->getCache(
      'cache_pages'
    );
    $pageSectionCache = $GLOBALS['typo3CacheManager']->getCache(
      'cache_pagesection'
    );
    $pageCache->flushByTags($tags);
    $pageSectionCache->flushByTags($tags);
    }
  }
}

4) Hooking into processdatamap could then call clear_cache_by_tags() to
flush the appropriate cache entries.

What do you think?

--
cheers,
Steffen

TYPO3 Blog: http://www.t3node.com/
Blubber on Twitter: http://twitter.com/t3node
_______________________________________________
TYPO3-dev mailing list
TYPO3-dev@...
http://lists.netfielders.de/cgi-bin/mailman/listinfo/typo3-dev