The best way to cache Presenter->link() ?

4 years ago

David Šolc
Member | 3
+
+1
-

I am rendering a lot of data in overview template. There was no point to paginate the result till now, so I was rendering all of data (±1000 rows) in a table. It was ok until I added some links (4) to each row.

Suddenly response time was much longer, so I profiled the request and here is the result.

http://postimg.org/image/90n3qd39f

10.4+8.9+5.7+4.9+4.7 = 34.6% of time is taking link() method

Here is a result without links.

http://postimg.org/…e/cybdudfnf/

So, I was wondering, what is the best way to cache links?

Thank you for any hints.

4 years ago

Oli
Member | 1221
+
0
-

I think problem is in your router. I would say you use database without cache in router, dont you? Use cache for your database query eg. id => slug.

4 years ago

David Grudl
Nette Core | 6877
+
+7
-
{var $magic = 9999}
{capture $link}{link Product:detail $magic}{/capture}

{foreach $products as $product}
    <a href="{$link|replace:$magic:$product->id}">...</a>
{/foreach}