Cache/nl: Difference between revisions
From Joomla! Documentation
No edit summary |
Updating to match new version of source page |
||
| (14 intermediate revisions by 3 users not shown) | |||
| Line 1: | Line 1: | ||
<noinclude><languages /></noinclude> | <noinclude><languages /></noinclude> | ||
= | <div lang="en" dir="ltr" class="mw-content-ltr"> | ||
Joomla has different ways of caching "things". Here is an overview for administrators and developers – what, where and when. | |||
</div> | |||
<div lang="en" dir="ltr" class="mw-content-ltr"> | |||
== For Administrators == | |||
</div> | |||
<div lang="en" dir="ltr" class="mw-content-ltr"> | |||
As an administrator, Joomla provides you with the ability to cache parts of your site. You can choose to cache whole web pages or just parts of those pages. This guide explains how. | As an administrator, Joomla provides you with the ability to cache parts of your site. You can choose to cache whole web pages or just parts of those pages. This guide explains how. | ||
</div> | |||
On a Joomla site web page there are 3 things | <span lang="en" dir="ltr" class="mw-content-ltr">On a Joomla site web page there are 3 things that may be cached:</span> | ||
<div lang="en" dir="ltr" class="mw-content-ltr"> | |||
# The whole page itself – the Page cache | # The whole page itself – the Page cache | ||
# The output from the Joomla component for that web page – known as the View cache | # The output from the Joomla component for that web page – known as the View cache | ||
# The output from the modules shown on that page – known as the Module cache | # The output from the modules shown on that page – known as the Module cache | ||
You have a number of cache settings | </div> | ||
# The system plugin | <span lang="en" dir="ltr" class="mw-content-ltr">You have a number of cache settings that allow you to control what gets cached:</span> | ||
# The Global Configuration, System tab, Cache Settings. Here the System Cache option may be set to | <div lang="en" dir="ltr" class="mw-content-ltr"> | ||
# The system plugin ''System – Page Cache'' | |||
# The Global Configuration, System tab, Cache Settings. Here the System Cache option may be set to | |||
#* OFF – Caching disabled | #* OFF – Caching disabled | ||
#* ON – Conservative caching | #* ON – Conservative caching | ||
#* ON – Progressive caching | #* ON – Progressive caching | ||
# Many modules within their options have an Advanced tab in which the Caching can be set to Use global or No caching | # Many modules within their options have an Advanced tab in which the Caching can be set to ''Use global'' or ''No caching'' | ||
As described below, there are also rules for caching | </div> | ||
<span lang="en" dir="ltr" class="mw-content-ltr">As described below, there are also rules for caching that are implemented within the Joomla code, and over which you have no control.</span> | |||
You can clear the cache through the | <span lang="en" dir="ltr" class="mw-content-ltr">You can clear the cache through the {{rarr|Administrator,System,Clear Cache}} menu selection.</span> | ||
In general, you can think of Joomla having 3 levels of cache, increasing in | <div lang="en" dir="ltr" class="mw-content-ltr"> | ||
In general, you can think of Joomla having 3 levels of cache, increasing in aggressiveness | |||
</div> | |||
<div lang="en" dir="ltr" class="mw-content-ltr"> | |||
# Conservative caching | # Conservative caching | ||
# Progressive caching | # Progressive caching | ||
# Page caching | # Page caching | ||
We'll look at these three in detail below. | </div> | ||
<span lang="en" dir="ltr" class="mw-content-ltr">We'll look at these three in detail below.</span> | |||
In addition, Joomla developers can use caching facilities to store the result of database queries for example, to increase the responsiveness of the site, but this is outside the scope of | <span lang="en" dir="ltr" class="mw-content-ltr">In addition, Joomla developers can use caching facilities to store the result of database queries, for example, to increase the responsiveness of the site, but this is outside the scope of Administrator capabilities.</span> | ||
<div lang="en" dir="ltr" class="mw-content-ltr"> | |||
== Page Caching == | == Page Caching == | ||
To switch this on, go to | </div> | ||
<span lang="en" dir="ltr" class="mw-content-ltr">To switch this on, go to {{rarr|Administrator,Extensions,Plugins}}. Then find the System – Page Cache plugin, and enable it. This means that site pages will now be cached and whenever they're requested again, the cached page will be served, rather than it being generated by Joomla from the information in the database. The cached page will continue to be served until it's expired – as defined by the ''Cache Time'' parameter in the {{rarr|Administrator,Global Configuration,System tab,Cache Settings}}.</span> | |||
If you're reading this page as a tutorial and want to test the page caching, | <span lang="en" dir="ltr" class="mw-content-ltr">If you're reading this page as a tutorial and want to test the page caching, it's best to set the Global Configuration cache settings to:</span> | ||
<div lang="en" dir="ltr" class="mw-content-ltr"> | |||
* Cache Handler – File | * Cache Handler – File | ||
* Path to Cache Folder – leave blank | * Path to Cache Folder – leave blank | ||
* Cache Time – 15 (the default of 15 minutes) | * Cache Time – 15 (the default of 15 minutes) | ||
* Platform Specific Caching - No | |||
* System Cache – OFF – Caching disabled | * System Cache – OFF – Caching disabled | ||
To | </div> | ||
<span lang="en" dir="ltr" class="mw-content-ltr">To verify that page caching is working, go to a website page that displays an article. After you display that page you should find in the file system a ''cache/page'' directory with a file in it that has a filename like ''<string of hex digits>-cache-page-<string of hex digits>.php''. (Joomla has to store separate cache pages for separate URLs so the second string of hex digits is a hash of the URL of the site web page, to make the filename unique to that page).</span> | |||
Then use the | <span lang="en" dir="ltr" class="mw-content-ltr">Then use the Administrator functionality to change the text of that article, and redisplay the site web page. You should find the cached version, not your modified text.</span> | ||
Changing an article (or other Joomla item) does not clear the page cache for the | <div lang="en" dir="ltr" class="mw-content-ltr"> | ||
To clear the page cache go to | Changing an article (or other Joomla item) does not clear the page cache for the web page(s) where that article is displayed. | ||
To clear the page cache go to {{rarr|Administrator,System,Clear Cache}}. Click on the checkbox next to the ''Cache Group'' called "page", and press the Delete button. When you redisplay your web page it should now show your amended text. | |||
</div> | |||
If your site has a function like a shopping basket | <span lang="en" dir="ltr" class="mw-content-ltr">If your site has a function like a shopping basket, applying page caching will cause problems, as pages have to show what the customer has already selected, rather than displaying a cached page that is common to everyone. However, you can configure the System - Page Cache plugin to exclude caching specified Menu Items or specified URLs and URL ranges (in the Advanced tab), so that only truly static pages are cached.</span> | ||
<div lang="en" dir="ltr" class="mw-content-ltr"> | |||
== Conservative Caching == | == Conservative Caching == | ||
With Conservative Caching you can cache the View output from components and the output from those Modules | </div> | ||
<span lang="en" dir="ltr" class="mw-content-ltr">With Conservative Caching you can cache the View output from components and the output from those Modules that allow caching. But note that this will work only on pages that are not cached using the Page Cache. For those pages the whole web page is cached, and Conservative Caching isn't even considered.</span> | |||
To switch on Conservative Caching: | <span lang="en" dir="ltr" class="mw-content-ltr">To switch on Conservative Caching:</span> | ||
# Go to | <div lang="en" dir="ltr" class="mw-content-ltr"> | ||
# Go to Extensions | # Go to {{rarr|Administrator,System,Global Configuration,System tab}} and within Cache Settings, set System Cache to ON – Conservative caching | ||
# Go to {{rarr|Administrator,Extensions,Modules}} and select the modules that you'd like to be cached. If that module permits caching then under the Advanced tab you should be able to set Caching to | |||
</div> | |||
<div lang="en" dir="ltr" class="mw-content-ltr"> | |||
* Use Global – this module will be cached (with the Global option now having been set to Conservative caching) | * Use Global – this module will be cached (with the Global option now having been set to Conservative caching) | ||
* No caching – this module will not be cached. | * No caching – this module will not be cached. | ||
(Note that the Cache Time in the Global Configuration is in minutes but the Cache Time in the Module settings is in seconds.) | </div> | ||
<span lang="en" dir="ltr" class="mw-content-ltr">(Note that the Cache Time in the Global Configuration is in minutes but the Cache Time in the Module settings is in seconds.)</span> | |||
To check it's working, go to your site, '''ensure that you are logged out''', and navigate to a web page | <span lang="en" dir="ltr" class="mw-content-ltr">To check it's working, go to your site, '''ensure that you are logged out''', and navigate to a web page that displays an article. Check your file system and you should find a folder ''cache/com_content'' containing a cache file.</span> | ||
You'll also find other directories such as | <span lang="en" dir="ltr" class="mw-content-ltr">You'll also find other directories such as ''cache/com_languages'' (as displaying the page involves loading the current language, and this will be cached as well) and also directories relating to module cache, e.g. ''cache/com_modules''. These result from the use of cache that developers have coded within the Joomla application.</span> | ||
If you edit and save that article | <span lang="en" dir="ltr" class="mw-content-ltr">If you edit and save that article then refresh the site page, you will find that the site displays the updated text this time. This is because whenever the edit is saved, Joomla clears the cache for that article.</span> | ||
However, you can demonstrate that the cache is working if you edit the cache file in the | <span lang="en" dir="ltr" class="mw-content-ltr">However, you can demonstrate that the cache is working if you edit the cache file in the ''cache/com_content'' directory using a basic text editor. Using the editor, change one letter within the article text in the cache file and save the file. Then when you refresh the web page you should see the change that you made to the cache file.</span> | ||
How can you select which component views get cached, and under what circumstances? Alas, you can't do this. This is determined by the Joomla core component developers and coded in the component | <span lang="en" dir="ltr" class="mw-content-ltr">How can you select which component views get cached, and under what circumstances? Alas, you can't do this. This is determined by the Joomla core component developers and coded in the component PHP code. The criteria are different for each component. However, you can easily discover what criteria are used because for each of the site components they are coded in the site ''controller.php'' file. For example, at the time of this writing (Joomla version 3.9.2) for the Contacts component we find in ''components/com_contact/controller.php''</span> | ||
< | <syntaxhighlight lang="php"> | ||
if (JFactory::getApplication()->getUserState('com_contact.contact.data') === null) | if (JFactory::getApplication()->getUserState('com_contact.contact.data') === null) | ||
{ | { | ||
$cachable = true; | $cachable = true; | ||
} | } | ||
</ | </syntaxhighlight> | ||
This means that the views associated with contacts will be cachable unless there is session data keyed by com_contact.contact.data – | <span lang="en" dir="ltr" class="mw-content-ltr">This means that the views associated with contacts will be cachable unless there is session data keyed by com_contact.contact.data – that will be the case if in the user session the user has displayed a contact form (e.g. on a page pointed to by a menu item of type Contacts → Single Contact).</span> | ||
The equivalent file for articles | <span lang="en" dir="ltr" class="mw-content-ltr">The equivalent file for articles ''components/com_content/controller.php'' contains:</span> | ||
< | <syntaxhighlight lang="php"> | ||
$cachable = true; | $cachable = true; | ||
if ($user->get('id') || ($this->input->getMethod() === 'POST' && (($vName === 'category' && $this->input->get('layout') !== 'blog') || $vName === 'archive' ))) | if ($user->get('id') || ($this->input->getMethod() === 'POST' && (($vName === 'category' && $this->input->get('layout') !== 'blog') || $vName === 'archive' ))) | ||
| Line 82: | Line 109: | ||
$cachable = false; | $cachable = false; | ||
} | } | ||
</ | </syntaxhighlight> | ||
The expression | <span lang="en" dir="ltr" class="mw-content-ltr">The expression ''$user->get('id')'' is true if this is a logged-in user. This means that articles are never cached for logged-in users. The subsequent expressions relate to other conditions when the caching is not performed, even if the user is not logged in.</span> | ||
<span lang="en" dir="ltr" class="mw-content-ltr">In this way you can discover the circumstances under which caching is performed, but changing these is not advisable.</span> | |||
You can also demonstrate that modules are being cached by using the Joomla Breadcrumbs module, ensuring it's displayed in some module position on the | <div lang="en" dir="ltr" class="mw-content-ltr"> | ||
You can also demonstrate that modules are being cached by using the Joomla Breadcrumbs module, ensuring it's displayed in some module position on the web page, setting its Caching option and manually editing the cached file in cache/mod_breadcrumbs. | |||
</div> | |||
== Progressive Caching == | <div lang="en" dir="ltr" class="mw-content-ltr"> | ||
Like Conservative Caching, Progressive Caching also caches the output from component views and from modules. The functional difference between the two is that with Progressive Caching '''for logged-off users all modules are always cached'''. In this case setting the No | == Progressive Caching == | ||
</div> | |||
<span lang="en" dir="ltr" class="mw-content-ltr">Like Conservative Caching, Progressive Caching also caches the output from component views and from modules. The functional difference between the two is that with Progressive Caching '''for logged-off users all modules are always cached'''. In this case, setting the ''No Caching'' option for a module has no effect. If the caching storage option is to ''File'', you can find the modules cache file (the output from all modules is stored within the same file) within the ''cache/com_modules'' directory.</span> | |||
To switch on | <span lang="en" dir="ltr" class="mw-content-ltr">To switch on Progressive Caching, go to {{rarr|Administrator,System,Global Configuration,System tab}} and within ''Cache Settings'' set ''System Cache'' to ''ON – Progressive caching''.</span> | ||
As regards the conditions for caching of Joomla core component views '''there is no difference between conservative and progressive caching'''. Despite what you may read on some websites and responses to | <span lang="en" dir="ltr" class="mw-content-ltr">As regards the conditions for caching of Joomla core component views, '''there is no difference between conservative and progressive caching'''. Despite what you may read on some websites and responses to Stack Overflow questions, it is not the case that Conservative Caching relates to when the user is not logged on and Progressive Caching to when the user is logged on.</span> | ||
<div lang="en" dir="ltr" class="mw-content-ltr"> | |||
== Summary == | == Summary == | ||
A summary of the caching types is below. | </div> | ||
<span lang="en" dir="ltr" class="mw-content-ltr">A summary of the caching types is below.</span> | |||
===Page Caching=== | <div lang="en" dir="ltr" class="mw-content-ltr"> | ||
*'''Configuration''': Built-in Plugin (Extensions | === Page Caching === | ||
</div> | |||
<div lang="en" dir="ltr" class="mw-content-ltr"> | |||
*'''Configuration''': Built-in Plugin ({{rarr|Administrator,Extensions,Plugin Manager,System - Page Cache}}) | |||
*'''Caches''': each whole page of your site | *'''Caches''': each whole page of your site | ||
*'''Based on''': URL | *'''Based on''': URL | ||
</div> | |||
<div lang="en" dir="ltr" class="mw-content-ltr"> | |||
*'''More info''': | *'''More info''': | ||
**Optional browser caching: Also caches on your visitors' browser/computer | **Optional browser caching: Also caches on your visitors' browser/computer | ||
**Only caches pages for guest visitors (not for logged in visitors). Be careful using this plugin if you have an interactive site where you want to server content based on session/cookie information rather than on the plain URL only. Features like a shopping cart will not work. | **Only caches pages for guest visitors (not for logged in visitors). Be careful using this plugin if you have an interactive site where you want to server content based on session/cookie information rather than on the plain URL only. Features like a shopping cart will not work. | ||
</div> | |||
<div class="mw-translate-fuzzy"> | <div class="mw-translate-fuzzy"> | ||
== | ===Weergave caching=== | ||
</div> | </div> | ||
<div class="mw-translate-fuzzy"> | |||
*'''Systeem''': Algemene instellingen->Cache | *'''Systeem''': Algemene instellingen->Cache | ||
*'''Caches''': elke weergave van een component | *'''Caches''': elke weergave van een component | ||
*'''Based on''': URL, weerrgave, parameters, ... | *'''Based on''': URL, weerrgave, parameters, ... | ||
*'''Meer informatie''': Component ontwikkelaars dienen dit in de code toe te voegen om het te laten werken. Dit word meestal nagelaten. De Joomla main content component gebruikt dit, maar enkel voor gastbezoekers van de website maar dit is niet verplicht voor elk component. | *'''Meer informatie''': Component ontwikkelaars dienen dit in de code toe te voegen om het te laten werken. Dit word meestal nagelaten. De Joomla main content component gebruikt dit, maar enkel voor gastbezoekers van de website maar dit is niet verplicht voor elk component. | ||
</div> | |||
<div class="mw-translate-fuzzy"> | <div class="mw-translate-fuzzy"> | ||
==Module Caching== | ===Module Caching=== | ||
</div> | </div> | ||
*'''Configuration''': Global Config->Cache | <div lang="en" dir="ltr" class="mw-content-ltr"> | ||
*'''Configuration''': Global Config -> Cache | |||
*'''Caches''': each module (individually customized via each module's Advanced Parameters) | *'''Caches''': each module (individually customized via each module's Advanced Parameters) | ||
*'''Based on''': the module id, the user's view levels and the Itemid parameter in the HTTP request | *'''Based on''': the module id, the user's view levels and the ''Itemid'' parameter in the HTTP request | ||
*'''More info''': You must disable it on some modules to avoid problems | *'''More info''': You must disable it on some modules to avoid problems | ||
</div> | |||
<div class="mw-translate-fuzzy"> | <div class="mw-translate-fuzzy"> | ||
== | ===Meer Caching=== | ||
</div> | </div> | ||
If you want to check out other cache systems and possibilities, you might want to check out the third-party extensions around caching. | <span lang="en" dir="ltr" class="mw-content-ltr">If you want to check out other cache systems and possibilities, you might want to check out the third-party extensions around caching.</span> | ||
<div class="mw-translate-fuzzy"> | <div class="mw-translate-fuzzy"> | ||
==Caching | ==Caching activering of opslagplaatsen== | ||
*''' | </div> | ||
<div lang="en" dir="ltr" class="mw-content-ltr"> | |||
*'''Configuration''': {{rarr|Global Config,Cache}} | |||
Here you can choose which system you want your site to use for all caching. Some options are: APC, Eaccelorator, File, Memcache, Redis, XCache. | |||
</div> | </div> | ||
APC, bijvoorbeeld, slaat ook uw | APC, bijvoorbeeld, slaat ook uw PHP opcode (operationele code) op. | ||
<div class="mw-translate-fuzzy"> | <div class="mw-translate-fuzzy"> | ||
=Voor | =Voor ontwikkelaars= | ||
</div> | </div> | ||
The class '''JCache''' allows a lot of different sorts and levels of caching. | <span lang="en" dir="ltr" class="mw-content-ltr">The class '''JCache''' allows a lot of different sorts and levels of caching. The following subclasses are made specifically, but you can add your own, or use the main one in many different ways.</span> | ||
Onthoudt dat het eerste niveau van het aangetroffen cache, opgeheven zal worden boven een diepere caching. Ik veronderstel dat dat te veel niveaus is ook contraproductief is ("moet nog geverifieerd worden"). | Onthoudt dat het eerste niveau van het aangetroffen cache, opgeheven zal worden boven een diepere caching. Ik veronderstel dat dat te veel niveaus is ook contraproductief is ("moet nog geverifieerd worden"). | ||
*'''JCacheView''' cached en geeft de uitkomst van een weergave (in MVC). | *'''JCacheView''' cached en geeft de uitkomst van een weergave (in MVC). Een cache id word automatisch aangemaakt vanuit de URI, specifieke weergave en de specifieke method, of deze is zelf toe te kennen. | ||
Dit kan automatisch worden gedaan via het base-controller weergave functie. Bijvoorbeeld in de controller van het onderdeel: | Dit kan automatisch worden gedaan via het base-controller weergave functie. Bijvoorbeeld in de controller van het onderdeel: | ||
< | <syntaxhighlight lang="php">class DeliciousController extends JController { | ||
function display() { | function display() { | ||
parent::display(true); //true asks for caching. | parent::display(true); //true asks for caching. | ||
} | } | ||
}</ | }</syntaxhighlight> | ||
<div class="mw-translate-fuzzy"> | |||
Er zijn ook nog sommige urlparams om aan te denken. Zie hier: [http://joomla.stackexchange.com/questions/5781/how-can-i-use-joomlas-cache-with-my-components-view/7000#7000 "joomla stack"] | Er zijn ook nog sommige urlparams om aan te denken. Zie hier: [http://joomla.stackexchange.com/questions/5781/how-can-i-use-joomlas-cache-with-my-components-view/7000#7000 "joomla stack"] | ||
</div> | |||
<div class="mw-translate-fuzzy"> | |||
Let op, bij updates (zoals such as hits of bezoekrs aantallen) zullen NIET worden bijgewerkt (of het zou moeten zijn dat dit gebeurd buiten deze method en dus nog dieper in de code MVC-part.) | Let op, bij updates (zoals such as hits of bezoekrs aantallen) zullen NIET worden bijgewerkt (of het zou moeten zijn dat dit gebeurd buiten deze method en dus nog dieper in de code MVC-part.) | ||
</div> | |||
*'''JCachePage''' cached en geeft de inhoud van de pagina weer. | *'''JCachePage''' cached en geeft de inhoud van de pagina weer. | ||
*'''JCacheCallback''' cached en geeft de uitkomst en resultaten van functies of methods. | *'''JCacheCallback''' cached en geeft de uitkomst en resultaten van functies of methods. | ||
Indien queries moeten worden gecahed, is dit een goede class er voor, zoals hier weergegeven: [[S:MyLanguage/ | Indien queries moeten worden gecahed, is dit een goede class er voor, zoals hier weergegeven: [[S:MyLanguage/Using_caching_to_speed_up_your_code|Het gebruik van caching voor de versnelling van de code]] | ||
*'''JCacheOutput''' cached en geeft output. | *'''JCacheOutput''' cached en geeft output. | ||
Dit is bedoeld voor caching van een specifiek deel van de | Dit is bedoeld voor caching van een specifiek deel van de PHP code. Het werkt als een uitvoerbuffer, maar gecached. | ||
<div class="mw-translate-fuzzy"> | |||
== Verwijzingen == | == Verwijzingen == | ||
* [ | </div> | ||
* [https://api.joomla.org/cms-3/classes/ | * [https://forum.joomla.org/viewtopic.php?f=428&t=326990&start=0 Better performance with Joomla System Cache plugin (Joomla Forum)] | ||
* [ | * [https://api.joomla.org/cms-3/classes/Joomla.CMS.Cache.Cache.html JCache] | ||
* [https://joomla.stackexchange.com/questions/5781/how-can-i-use-joomlas-cache-with-my-components-view/7000#7000 Hoe gebruik ik Joomla's Cache samen met de weergave van componenten? (joomla stackexchange beta)] | |||
<noinclude> | <noinclude> | ||
Latest revision as of 09:48, 2 October 2024
Joomla has different ways of caching "things". Here is an overview for administrators and developers – what, where and when.
For Administrators
As an administrator, Joomla provides you with the ability to cache parts of your site. You can choose to cache whole web pages or just parts of those pages. This guide explains how.
On a Joomla site web page there are 3 things that may be cached:
- The whole page itself – the Page cache
- The output from the Joomla component for that web page – known as the View cache
- The output from the modules shown on that page – known as the Module cache
You have a number of cache settings that allow you to control what gets cached:
- The system plugin System – Page Cache
- The Global Configuration, System tab, Cache Settings. Here the System Cache option may be set to
- OFF – Caching disabled
- ON – Conservative caching
- ON – Progressive caching
- Many modules within their options have an Advanced tab in which the Caching can be set to Use global or No caching
As described below, there are also rules for caching that are implemented within the Joomla code, and over which you have no control.
You can clear the cache through the Administrator → System → Clear Cache menu selection.
In general, you can think of Joomla having 3 levels of cache, increasing in aggressiveness
- Conservative caching
- Progressive caching
- Page caching
We'll look at these three in detail below.
In addition, Joomla developers can use caching facilities to store the result of database queries, for example, to increase the responsiveness of the site, but this is outside the scope of Administrator capabilities.
Page Caching
To switch this on, go to Administrator → Extensions → Plugins. Then find the System – Page Cache plugin, and enable it. This means that site pages will now be cached and whenever they're requested again, the cached page will be served, rather than it being generated by Joomla from the information in the database. The cached page will continue to be served until it's expired – as defined by the Cache Time parameter in the Administrator → Global Configuration → System tab → Cache Settings.
If you're reading this page as a tutorial and want to test the page caching, it's best to set the Global Configuration cache settings to:
- Cache Handler – File
- Path to Cache Folder – leave blank
- Cache Time – 15 (the default of 15 minutes)
- Platform Specific Caching - No
- System Cache – OFF – Caching disabled
To verify that page caching is working, go to a website page that displays an article. After you display that page you should find in the file system a cache/page directory with a file in it that has a filename like <string of hex digits>-cache-page-<string of hex digits>.php. (Joomla has to store separate cache pages for separate URLs so the second string of hex digits is a hash of the URL of the site web page, to make the filename unique to that page).
Then use the Administrator functionality to change the text of that article, and redisplay the site web page. You should find the cached version, not your modified text.
Changing an article (or other Joomla item) does not clear the page cache for the web page(s) where that article is displayed. To clear the page cache go to Administrator → System → Clear Cache. Click on the checkbox next to the Cache Group called "page", and press the Delete button. When you redisplay your web page it should now show your amended text.
If your site has a function like a shopping basket, applying page caching will cause problems, as pages have to show what the customer has already selected, rather than displaying a cached page that is common to everyone. However, you can configure the System - Page Cache plugin to exclude caching specified Menu Items or specified URLs and URL ranges (in the Advanced tab), so that only truly static pages are cached.
Conservative Caching
With Conservative Caching you can cache the View output from components and the output from those Modules that allow caching. But note that this will work only on pages that are not cached using the Page Cache. For those pages the whole web page is cached, and Conservative Caching isn't even considered.
To switch on Conservative Caching:
- Go to Administrator → System → Global Configuration → System tab and within Cache Settings, set System Cache to ON – Conservative caching
- Go to Administrator → Extensions → Modules and select the modules that you'd like to be cached. If that module permits caching then under the Advanced tab you should be able to set Caching to
- Use Global – this module will be cached (with the Global option now having been set to Conservative caching)
- No caching – this module will not be cached.
(Note that the Cache Time in the Global Configuration is in minutes but the Cache Time in the Module settings is in seconds.)
To check it's working, go to your site, ensure that you are logged out, and navigate to a web page that displays an article. Check your file system and you should find a folder cache/com_content containing a cache file.
You'll also find other directories such as cache/com_languages (as displaying the page involves loading the current language, and this will be cached as well) and also directories relating to module cache, e.g. cache/com_modules. These result from the use of cache that developers have coded within the Joomla application.
If you edit and save that article then refresh the site page, you will find that the site displays the updated text this time. This is because whenever the edit is saved, Joomla clears the cache for that article.
However, you can demonstrate that the cache is working if you edit the cache file in the cache/com_content directory using a basic text editor. Using the editor, change one letter within the article text in the cache file and save the file. Then when you refresh the web page you should see the change that you made to the cache file.
How can you select which component views get cached, and under what circumstances? Alas, you can't do this. This is determined by the Joomla core component developers and coded in the component PHP code. The criteria are different for each component. However, you can easily discover what criteria are used because for each of the site components they are coded in the site controller.php file. For example, at the time of this writing (Joomla version 3.9.2) for the Contacts component we find in components/com_contact/controller.php
if (JFactory::getApplication()->getUserState('com_contact.contact.data') === null)
{
$cachable = true;
}
This means that the views associated with contacts will be cachable unless there is session data keyed by com_contact.contact.data – that will be the case if in the user session the user has displayed a contact form (e.g. on a page pointed to by a menu item of type Contacts → Single Contact).
The equivalent file for articles components/com_content/controller.php contains:
$cachable = true;
if ($user->get('id') || ($this->input->getMethod() === 'POST' && (($vName === 'category' && $this->input->get('layout') !== 'blog') || $vName === 'archive' )))
{
$cachable = false;
}
The expression $user->get('id') is true if this is a logged-in user. This means that articles are never cached for logged-in users. The subsequent expressions relate to other conditions when the caching is not performed, even if the user is not logged in.
In this way you can discover the circumstances under which caching is performed, but changing these is not advisable.
You can also demonstrate that modules are being cached by using the Joomla Breadcrumbs module, ensuring it's displayed in some module position on the web page, setting its Caching option and manually editing the cached file in cache/mod_breadcrumbs.
Progressive Caching
Like Conservative Caching, Progressive Caching also caches the output from component views and from modules. The functional difference between the two is that with Progressive Caching for logged-off users all modules are always cached. In this case, setting the No Caching option for a module has no effect. If the caching storage option is to File, you can find the modules cache file (the output from all modules is stored within the same file) within the cache/com_modules directory.
To switch on Progressive Caching, go to Administrator → System → Global Configuration → System tab and within Cache Settings set System Cache to ON – Progressive caching.
As regards the conditions for caching of Joomla core component views, there is no difference between conservative and progressive caching. Despite what you may read on some websites and responses to Stack Overflow questions, it is not the case that Conservative Caching relates to when the user is not logged on and Progressive Caching to when the user is logged on.
Summary
A summary of the caching types is below.
Page Caching
- Configuration: Built-in Plugin (Administrator → Extensions → Plugin Manager → System - Page Cache)
- Caches: each whole page of your site
- Based on: URL
- More info:
- Optional browser caching: Also caches on your visitors' browser/computer
- Only caches pages for guest visitors (not for logged in visitors). Be careful using this plugin if you have an interactive site where you want to server content based on session/cookie information rather than on the plain URL only. Features like a shopping cart will not work.
Weergave caching
- Systeem: Algemene instellingen->Cache
- Caches: elke weergave van een component
- Based on: URL, weerrgave, parameters, ...
- Meer informatie: Component ontwikkelaars dienen dit in de code toe te voegen om het te laten werken. Dit word meestal nagelaten. De Joomla main content component gebruikt dit, maar enkel voor gastbezoekers van de website maar dit is niet verplicht voor elk component.
Module Caching
- Configuration: Global Config -> Cache
- Caches: each module (individually customized via each module's Advanced Parameters)
- Based on: the module id, the user's view levels and the Itemid parameter in the HTTP request
- More info: You must disable it on some modules to avoid problems
Meer Caching
If you want to check out other cache systems and possibilities, you might want to check out the third-party extensions around caching.
Caching activering of opslagplaatsen
- Configuration: Global Config → Cache
Here you can choose which system you want your site to use for all caching. Some options are: APC, Eaccelorator, File, Memcache, Redis, XCache.
APC, bijvoorbeeld, slaat ook uw PHP opcode (operationele code) op.
Voor ontwikkelaars
The class JCache allows a lot of different sorts and levels of caching. The following subclasses are made specifically, but you can add your own, or use the main one in many different ways.
Onthoudt dat het eerste niveau van het aangetroffen cache, opgeheven zal worden boven een diepere caching. Ik veronderstel dat dat te veel niveaus is ook contraproductief is ("moet nog geverifieerd worden").
- JCacheView cached en geeft de uitkomst van een weergave (in MVC). Een cache id word automatisch aangemaakt vanuit de URI, specifieke weergave en de specifieke method, of deze is zelf toe te kennen.
Dit kan automatisch worden gedaan via het base-controller weergave functie. Bijvoorbeeld in de controller van het onderdeel:
class DeliciousController extends JController {
function display() {
parent::display(true); //true asks for caching.
}
}
Er zijn ook nog sommige urlparams om aan te denken. Zie hier: "joomla stack"
Let op, bij updates (zoals such as hits of bezoekrs aantallen) zullen NIET worden bijgewerkt (of het zou moeten zijn dat dit gebeurd buiten deze method en dus nog dieper in de code MVC-part.)
- JCachePage cached en geeft de inhoud van de pagina weer.
- JCacheCallback cached en geeft de uitkomst en resultaten van functies of methods.
Indien queries moeten worden gecahed, is dit een goede class er voor, zoals hier weergegeven: Het gebruik van caching voor de versnelling van de code
- JCacheOutput cached en geeft output.
Dit is bedoeld voor caching van een specifiek deel van de PHP code. Het werkt als een uitvoerbuffer, maar gecached.