Cache/it: Difference between revisions

From Joomla! Documentation

Ino (talk | contribs)
Created page with "Su una pagina web del sito Joomla ci sono 3 cose che possono essere memorizzate nella cache:"
FuzzyBot (talk | contribs)
Updating to match new version of source page
 
(32 intermediate revisions by 2 users not shown)
Line 1: Line 1:
<noinclude><languages /></noinclude>
<noinclude><languages /></noinclude>
<br />
; Joomla ha diversi modi di memorizzare le "cose". Ecco una panoramica per amministratori e sviluppatori, cosa, dove e quando.


=Per gli amministratori=
<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>


Come amministratore, Joomla ti offre la possibilità di memorizzare nella cache parti del tuo sito. È possibile scegliere di memorizzare nella cache pagine web intere o solo parti di tali pagine. Questa guida spiega come.
<div lang="en" dir="ltr" class="mw-content-ltr">
== For Administrators ==
</div>


Su una pagina web del sito Joomla ci sono 3 cose che possono essere memorizzate nella cache:
<div lang="en" dir="ltr" class="mw-content-ltr">
# The whole page itself – the Page cache
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.
# The output from the Joomla component for that web page – known as the View cache
</div>
# The output from the modules shown on that page – known as the Module cache
You have a number of cache settings which 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 which are implemented within the Joomla code, and over which you have no control.


You can clear the cache through the administrator menu option System / Clear Cache.
<span class="mw-translate-fuzzy">Su una pagina web del sito Joomla ci sono 3 cose che possono essere memorizzate nella cache:</span>
In general, you can think of Joomla having 3 levels of cache, increasing in aggresiveness
# L'intera pagina stessa - la cache della pagina
# Conservative caching
# L'output dal componente Joomla per quella pagina Web, noto come visualizzazione di cache
# Progressive caching
# L'output dei moduli mostrati in quella pagina, noto come modulo del cache
# Page caching
<span class="mw-translate-fuzzy">Hai un certo numero di impostazioni della cache che ti permettono di controllare ciò che viene memorizzato nella cache:</span>
We'll look at these three in detail below.
<div class="mw-translate-fuzzy">
# Il plugin di sistema "System - Page Cache"
# La configurazione globale, la scheda Sistema, Impostazioni cache. Qui l'opzione System Cache può essere impostata su
# * OFF - Memorizzazione nella cache disabilitata
# * ON - Memorizzazione nella cache conservativa
# * ON: caching progressivo
# Molti moduli all'interno delle loro opzioni hanno una scheda Avanzate in cui è possibile impostare la memorizzazione nella cache su Usa cache globale o No
</div>
<span class="mw-translate-fuzzy">Come descritto di seguito, ci sono anche regole per la memorizzazione nella cache che sono implementate all'interno del codice Joomla e su cui non si ha alcun controllo.</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 administrator capabilities.  
<span class="mw-translate-fuzzy">È possibile cancellare la cache tramite l'opzione di menu amministratore Sistema / Cancella cache.</span>
<div class="mw-translate-fuzzy">
In generale, puoi pensare a Joomla con 3 livelli di cache, aumentando l'aggressività
</div>
# Conservazione nella cache conservativa
# Memorizzazione nella cache progressiva
# Cache delle pagine
Vedremo questi tre in dettaglio qui sotto.
 
<span class="mw-translate-fuzzy">Inoltre, gli sviluppatori di Joomla possono utilizzare le funzionalità di memorizzazione nella cache per archiviare il risultato delle query del database, ad esempio, per aumentare la reattività del sito, ma questo non rientra nell'ambito delle funzionalità dell'amministratore.</span>


== Page Caching ==
== Page Caching ==
To switch this on, go to administrator Extensions / Plugins, 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 Global Configuration / System / Cache Settings.  
<span class="mw-translate-fuzzy">Per accenderlo, vai su Estensioni amministratore / Plugin, trova il plugin System - Page Cache e abilitalo. Ciò significa che le pagine del sito verranno ora memorizzate nella cache e, ogni volta che vengono richieste nuovamente, verrà pubblicata la pagina cache, anziché essere generata da Joomla dalle informazioni nel database. La pagina memorizzata nella cache continuerà a essere pubblicata fino alla scadenza, come definito dal parametro Cache Time nelle impostazioni di Global Configuration / System / Cache.</span>


If you're reading this page as a tutorial and want to test the page caching, then it's best to set the Global Configuration cache settings to
<span class="mw-translate-fuzzy">Se stai leggendo questa pagina come un'esercitazione e vuoi testare la memorizzazione nella cache della pagina, allora è meglio impostare le impostazioni della cache della Configurazione globale su</span>
* Cache Handler File
<div class="mw-translate-fuzzy">
* Path to Cache Folder – leave blank
* Cache Handler - File
* Cache Time 15 (the default of 15 minutes)
* Percorso della cartella della cache: lasciare vuoto
* System Cache OFF – Caching disabled
* Cache Time - 15 (il valore predefinito di 15 minuti)
To check page caching is working, go to a site webpage which displays an article. After you display that page you should find in the file system a <tt>cache/page</tt> directory with a file in it which has a filename like <tt><string of hex digits>-cache-page-<string of hex digits>.php</tt>. (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 webpage, to make the filename unique to that page).  
* System Cache - OFF - Memorizzazione nella cache disabilitata
</div>
<span class="mw-translate-fuzzy">Per verificare il funzionamento della cache delle pagine, vai alla pagina web del sito che mostra un articolo. Dopo aver visualizzato quella pagina dovresti trovare nel file system una directory <tt>cache/page</ tt> con un file al suo interno che ha un nome di file come <tt><stringa di cifre esadecimali>-cache-page-<stringa di cifre esadecimali>.php</ tt>. (Joomla deve memorizzare pagine cache separate per URL separati in modo che la seconda stringa di cifre esadecimali sia un hash dell'URL della pagina web del sito, per rendere il nome file univoco per quella pagina).</span>


Then use the administrator functionality to change the text of that article, and redisplay the site webpage. You should find the cached version, not your modified text.
<span class="mw-translate-fuzzy">Quindi utilizzare la funzionalità di amministratore per modificare il testo dell'articolo e visualizzare nuovamente la pagina web del sito. Dovresti trovare la versione in cache, non il testo modificato.</span>


Changing an article (or other Joomla item) does not clear the page cache for the webpage(s) where that article is displayed.  
<div class="mw-translate-fuzzy">
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.
Cambiare un articolo (o un altro elemento di Joomla) non cancella la cache della pagina per la pagina web dove quell'articolo è visualizzato.  
Per cancellare la cache della pagina vai all'amministratore System / Clear Cache. Fare clic sulla casella di controllo accanto al Gruppo cache chiamato "pagina" e premere il pulsante Elimina. Quando si rivisualizza la pagina web dovrebbe ora mostrare il testo modificato.
</div>


If your site has a function like a shopping basket then applying page caching will cause problems, as pages have to show what the customer has already selected, rather than displaying a cached page which 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 class="mw-translate-fuzzy">Se il tuo sito ha una funzione come un carrello della spesa, l'applicazione del page caching causerà problemi, in quanto le pagine devono mostrare ciò che il cliente ha già selezionato, piuttosto che visualizzare una pagina memorizzata nella cache che è comune a tutti. Tuttavia, è possibile configurare il plugin System Page Cache per escludere la cache di voci di menu o URL e intervalli di URL specifici (nella scheda Avanzate), in modo che solo le pagine veramente statiche vengano memorizzate nella cache.</span>


== Conservative Caching ==
== Caching conservativo ==
With Conservative Caching you can cache the View output from components and the output from those Modules which allow caching. But note that this will work only on pages which are not cached using the Page Cache, as for those pages the whole webpage is cached, and Conservative Caching isn't even considered.
<span class="mw-translate-fuzzy">Con Conservative Caching è possibile mettere in cache l'output View dei componenti e l'output di quei moduli che permettono il caching. Ma si noti che questo funzionerà solo su pagine che non sono messe in cache usando la cache delle pagine, dato che per quelle pagine l'intera pagina web è in cache, e la cache conservativa non è nemmeno considerata.</span>


To switch on Conservative Caching:
Per attivare la caching conservativo:
# Go to administrator Global Configuration / System and within Cache Settings set System Cache to ON – Conservative caching
<div lang="en" dir="ltr" class="mw-content-ltr">
# Go to Extensions / Modules and select the modules which you'd like to be cached. If that module permits caching then under the Advanced tab you should be able to set Caching to  
# 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 which displays an article. Check your file system and you should find a folder <tt>cache/com_content</tt> containing a cache file.  
<span class="mw-translate-fuzzy">Per verificare che funzioni, vai al tuo sito '''' assicurati di essere disconnesso '''' e vai a una pagina web che mostra un articolo. Controlla il tuo file system e dovresti trovare una cartella <tt> cache / com_content </tt> contenente un file cache.</span>


You'll also find other directories such as <tt>cache/com_languages</tt> (as displaying the page involves loading the current language, and this will be cached as well) and also directories relating to module cache, eg <tt>cache/com_modules</tt>. These result from the use of cache which developers have coded within the Joomla application.  
<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, and 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 class="mw-translate-fuzzy">Se modifichi e salvi l'articolo, quindi aggiorni la pagina del sito, questa volta il sito visualizzerà il testo aggiornato. Questo perché ogni volta che la modifica viene salvata, Joomla svuota la cache per quell'articolo.</span>


However, you can demonstrate that the cache is working if you edit the cache file in the <tt>cache/com_content</tt> 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 webpage you should see the update which you made to the cache file.  
<span class="mw-translate-fuzzy">Tuttavia, è possibile dimostrare che la cache funziona se si modifica il file della cache nella directory <tt> cache / com_content </tt> utilizzando un editor di testo di base. Utilizzando l'editor, modifica una lettera all'interno del testo dell'articolo nel file della cache e salva il file. Quindi quando aggiorni la pagina web dovresti vedere l'aggiornamento che hai fatto al file cache.</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 php code. And 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 <tt>controller.php</tt> file. For example, at time of writing (Joomla version 3.9.2) for the contacts component we find in <tt>components/com_contact/controller.php</tt>
<span class="mw-translate-fuzzy">Come è possibile selezionare quali viste dei componenti vengono memorizzate nella cache e in quali circostanze? Ahimè, non puoi farlo. Ciò è determinato dagli sviluppatori del componente principale di Joomla e codificato nel codice php del componente. E i criteri sono diversi per ciascun componente. Tuttavia, puoi facilmente scoprire quali criteri vengono utilizzati perché per ciascuno dei componenti del sito sono codificati nel file <tt>controller.php</tt> del sito. Ad esempio, al momento della stesura (versione Joomla 3.9.2) per il componente contatti troviamo in <tt>components/com_contact / controller.php</tt></span>


<pre>
<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;
}
}
</pre>
</syntaxhighlight>


This means that the views associated with contacts will be cachable unless there is session data keyed by com_contact.contact.data – which will be the case if in the user session the user has displayed a contact form (eg on a page pointed to by a menuitem of type Contacts / Single Contact).
<span class="mw-translate-fuzzy">Questo significa che le viste associate ai contatti saranno accessibili a meno che non ci siano dati di sessione digitati da com_contact.contact.data - che sarà il caso se nella sessione utente l'utente ha visualizzato un modulo di contatto (ad esempio su una pagina indicata da un menuitem di tipo Contatti / Contatto singolo).</span>


The equivalent file for articles <tt>components/com_content/controller.php</tt> contains:
<span lang="en" dir="ltr" class="mw-content-ltr">The equivalent file for articles ''components/com_content/controller.php'' contains:</span>
<pre>
<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 100:
$cachable = false;
$cachable = false;
}
}
</pre>
</syntaxhighlight>


The expression <tt>$user->get('id')</tt> is true if this is a logged in user, so 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 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>


So in this way you can discover the circumstances under which caching is performed, but changing these is not advisable.  
<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 webpage, setting its Caching option and manually editing the cached file in cache/mod_breadcrumbs.
<div class="mw-translate-fuzzy">
Si può anche dimostrare che i moduli sono in cache utilizzando il modulo Joomla Breadcrumbs, assicurandosi che sia visualizzato in qualche posizione del modulo sulla pagina web, impostando la sua opzione Caching e modificando manualmente il file in cache/mod_breadcrumbs.
</div>


==  Progressive Caching ==  
==  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 '''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 then you can find the modules cache file (the output from all modules is stored within the same file) within the <tt>cache/com_modules</tt> directory.
<span class="mw-translate-fuzzy">Come il Conservative Caching, anche il Progressive Caching memorizza l'output dalle viste dei componenti e dai moduli. La differenza funzionale tra i due è che con il Progressive Caching ''tutti i moduli sono sempre in cache'''''. In questo caso, impostare l'opzione No caching per un modulo non ha alcun effetto. Se l'opzione caching storage è File allora si può trovare il file di cache dei moduli (l'output di tutti i moduli è memorizzato nello stesso file) all'interno della cartella <tt>cache/com_modules</tt>.</span>


To switch on progressive caching go to administrator Global Configuration / System and within Cache Settings set System Cache to ON – Progressive caching.
<span class="mw-translate-fuzzy">Per attivare la cache progressiva, passare all'amministratore Configurazione globale / Sistema e, all'interno delle impostazioni della cache, impostare la cache di sistema su ON - Cache progressiva.</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 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 class="mw-translate-fuzzy">Per quanto riguarda le condizioni per il caching di Joomla core component views '''non c'è differenza tra il caching conservativo e quello progressivo'''. Nonostante quello che si può leggere su alcuni siti web e le risposte alle domande di overflow stack, non è il caso che la cache conservativa si riferisce a quando l'utente non è connesso e la cache progressiva a quando l'utente è connesso.</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 -> Plugin Manager -> System - Page Cache)
=== 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>


===View Caching===
<div lang="en" dir="ltr" class="mw-content-ltr">
*'''Configuration''': Global Config->Cache
=== View Caching ===
</div>
<div lang="en" dir="ltr" class="mw-content-ltr">
*'''Configuration''': Global Config -> Cache
*'''Caches''': each view of a component
*'''Caches''': each view of a component
*'''Based on''': URL, view, parameters, ...
*'''Based on''': URL, view, parameters, ...
*'''More info''': Component developers have to include this in their code to work. Mostly this is not done. The Joomla main content component uses this, but only for guest visitors of your site though this is not obligated for every component.  
*'''More info''': Component developers have to include this in their code to work. Mostly this is not done. The Joomla main content component uses this, but only for guest visitors of your site though this is not obligated for every component.
===Module Caching===
</div>
*'''Configuration''': Global Config->Cache
<div lang="en" dir="ltr" class="mw-content-ltr">
=== Module Caching ===
</div>
<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>


===Further Caching===
<div 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.
=== Further Caching ===
</div>
<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>


===Caching engines or storages===
<div lang="en" dir="ltr" class="mw-content-ltr">
*'''Configuration''': Global Config->Cache
=== Caching Engines or Storage ===
Here you can choose which system you want your site to use for all caching. Current options are: APC, Eaccelorator, File, Memcache, Redis, XCache.
</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>


APC, for example, also caches your php opcode.
<div lang="en" dir="ltr" class="mw-content-ltr">
APC, for example, also caches your PHP opcode.
</div>


=For Developers=
<div lang="en" dir="ltr" class="mw-content-ltr">
The class '''JCache''' allows a lot of different sorts and levels of caching. The following sub-classes are made specifically, but you can add your own, or use the main one in many different ways.
= For Developers =
</div>
<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>


Don't forget that the first level of cache encountered, will override any deeper caching. I suppose that too many levels is also counterproductive (''to be verified though'').
<div lang="en" dir="ltr" class="mw-content-ltr">
*'''JCacheView''' caches and returns the output of a given view (in MVC). A cache id is automatically generated from the URI, specific view and its specific method, or you can give your own.
Don't forget that the first level of cache encountered, will override any deeper caching. I suppose that too many levels is also counterproductive (''to be verified though'').
</div>
<div lang="en" dir="ltr" class="mw-content-ltr">
*'''JCacheView''' caches and returns the output of a given view (in MVC). A cache id is automatically generated from the URI, specific view and its specific method, or you can give your own.
</div>
<div lang="en" dir="ltr" class="mw-content-ltr">
This can automatically be done via the base controller's display function. For example in the controller of your component:
This can automatically be done via the base controller's display function. For example in the controller of your component:
</div>


<source lang="php">class DeliciousController extends JController {
<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.
}
}
}</source>
}</syntaxhighlight>


There are also some urlparams to consider. Check this [http://joomla.stackexchange.com/questions/5781/how-can-i-use-joomlas-cache-with-my-components-view/7000#7000 "joomla stack"]
<div lang="en" dir="ltr" class="mw-content-ltr">
There are also some urlparams to consider. Check this [https://joomla.stackexchange.com/questions/5781/how-can-i-use-joomlas-cache-with-my-components-view/7000#7000 "joomla stack"]
</div>


Also, be aware that any updates (such as hits or visit counts) will NOT be updated (unless you add this outside this method and thus any deeper MVC-part.)
<div lang="en" dir="ltr" class="mw-content-ltr">
Also, be aware that any updates (such as hits or visit counts) will '''not''' be updated (unless you add this outside this method and thus any deeper MVC-part.)
</div>
<div lang="en" dir="ltr" class="mw-content-ltr">
*'''JCachePage''' caches and returns the body of the page.
*'''JCachePage''' caches and returns the body of the page.
*'''JCacheCallback''' caches and returns the output and results of functions or methods.
*'''JCacheCallback''' caches and returns the output and results of functions or methods.
If you want to cache queries, this is a good class for it, as illustrated here: [[S:MyLanguage/Using caching to speed up your code|Using caching to speed up your code]]
If you want to cache queries, this is a good class for it, as illustrated here: [[S:MyLanguage/Using_caching_to_speed_up_your_code|Using caching to speed up your code]]
</div>
<div lang="en" dir="ltr" class="mw-content-ltr">
*'''JCacheOutput''' caches and returns output.
*'''JCacheOutput''' caches and returns output.
This is rather meant for caching a specific part of php code. It acts like an output buffer, but cached.
This is rather meant for caching a specific part of PHP code. It acts like an output buffer, but cached.
</div>


==References==
<div lang="en" dir="ltr" class="mw-content-ltr">
* [http://forum.joomla.org/viewtopic.php?f=428&t=326990&start=0 Better performance with joomla System Cache plugin (Joomla Forum)]
== References ==
* [https://api.joomla.org/cms-3/classes/JCache.html JCache]
</div>
* [http://joomla.stackexchange.com/questions/5781/how-can-i-use-joomlas-cache-with-my-components-view/7000#7000 How can I use Joomla's Cache with my components view? (joomla stackexchange beta)]
<div lang="en" dir="ltr" class="mw-content-ltr">
* [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 How can I use Joomla's Cache with my components view? (joomla stackexchange beta)]
</div>


<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.

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.

Su una pagina web del sito Joomla ci sono 3 cose che possono essere memorizzate nella cache:

  1. L'intera pagina stessa - la cache della pagina
  2. L'output dal componente Joomla per quella pagina Web, noto come visualizzazione di cache
  3. L'output dei moduli mostrati in quella pagina, noto come modulo del cache

Hai un certo numero di impostazioni della cache che ti permettono di controllare ciò che viene memorizzato nella cache:

  1. Il plugin di sistema "System - Page Cache"
  2. La configurazione globale, la scheda Sistema, Impostazioni cache. Qui l'opzione System Cache può essere impostata su
  3. * OFF - Memorizzazione nella cache disabilitata
  4. * ON - Memorizzazione nella cache conservativa
  5. * ON: caching progressivo
  6. Molti moduli all'interno delle loro opzioni hanno una scheda Avanzate in cui è possibile impostare la memorizzazione nella cache su Usa cache globale o No

Come descritto di seguito, ci sono anche regole per la memorizzazione nella cache che sono implementate all'interno del codice Joomla e su cui non si ha alcun controllo.

È possibile cancellare la cache tramite l'opzione di menu amministratore Sistema / Cancella cache.

In generale, puoi pensare a Joomla con 3 livelli di cache, aumentando l'aggressività

  1. Conservazione nella cache conservativa
  2. Memorizzazione nella cache progressiva
  3. Cache delle pagine

Vedremo questi tre in dettaglio qui sotto.

Inoltre, gli sviluppatori di Joomla possono utilizzare le funzionalità di memorizzazione nella cache per archiviare il risultato delle query del database, ad esempio, per aumentare la reattività del sito, ma questo non rientra nell'ambito delle funzionalità dell'amministratore.

Page Caching

Per accenderlo, vai su Estensioni amministratore / Plugin, trova il plugin System - Page Cache e abilitalo. Ciò significa che le pagine del sito verranno ora memorizzate nella cache e, ogni volta che vengono richieste nuovamente, verrà pubblicata la pagina cache, anziché essere generata da Joomla dalle informazioni nel database. La pagina memorizzata nella cache continuerà a essere pubblicata fino alla scadenza, come definito dal parametro Cache Time nelle impostazioni di Global Configuration / System / Cache.

Se stai leggendo questa pagina come un'esercitazione e vuoi testare la memorizzazione nella cache della pagina, allora è meglio impostare le impostazioni della cache della Configurazione globale su

  • Cache Handler - File
  • Percorso della cartella della cache: lasciare vuoto
  • Cache Time - 15 (il valore predefinito di 15 minuti)
  • System Cache - OFF - Memorizzazione nella cache disabilitata

Per verificare il funzionamento della cache delle pagine, vai alla pagina web del sito che mostra un articolo. Dopo aver visualizzato quella pagina dovresti trovare nel file system una directory cache/page</ tt> con un file al suo interno che ha un nome di file come <stringa di cifre esadecimali>-cache-page-<stringa di cifre esadecimali>.php</ tt>. (Joomla deve memorizzare pagine cache separate per URL separati in modo che la seconda stringa di cifre esadecimali sia un hash dell'URL della pagina web del sito, per rendere il nome file univoco per quella pagina).

Quindi utilizzare la funzionalità di amministratore per modificare il testo dell'articolo e visualizzare nuovamente la pagina web del sito. Dovresti trovare la versione in cache, non il testo modificato.

Cambiare un articolo (o un altro elemento di Joomla) non cancella la cache della pagina per la pagina web dove quell'articolo è visualizzato. Per cancellare la cache della pagina vai all'amministratore System / Clear Cache. Fare clic sulla casella di controllo accanto al Gruppo cache chiamato "pagina" e premere il pulsante Elimina. Quando si rivisualizza la pagina web dovrebbe ora mostrare il testo modificato.

Se il tuo sito ha una funzione come un carrello della spesa, l'applicazione del page caching causerà problemi, in quanto le pagine devono mostrare ciò che il cliente ha già selezionato, piuttosto che visualizzare una pagina memorizzata nella cache che è comune a tutti. Tuttavia, è possibile configurare il plugin System Page Cache per escludere la cache di voci di menu o URL e intervalli di URL specifici (nella scheda Avanzate), in modo che solo le pagine veramente statiche vengano memorizzate nella cache.

Caching conservativo

Con Conservative Caching è possibile mettere in cache l'output View dei componenti e l'output di quei moduli che permettono il caching. Ma si noti che questo funzionerà solo su pagine che non sono messe in cache usando la cache delle pagine, dato che per quelle pagine l'intera pagina web è in cache, e la cache conservativa non è nemmeno considerata.

Per attivare la caching conservativo:

  1. Go to Administrator  System  Global Configuration  System tab and within Cache Settings, set System Cache to ON – Conservative caching
  2. 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.)

Per verificare che funzioni, vai al tuo sito ' assicurati di essere disconnesso ' e vai a una pagina web che mostra un articolo. Controlla il tuo file system e dovresti trovare una cartella cache / com_content contenente un file cache.

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.

Se modifichi e salvi l'articolo, quindi aggiorni la pagina del sito, questa volta il sito visualizzerà il testo aggiornato. Questo perché ogni volta che la modifica viene salvata, Joomla svuota la cache per quell'articolo.

Tuttavia, è possibile dimostrare che la cache funziona se si modifica il file della cache nella directory cache / com_content utilizzando un editor di testo di base. Utilizzando l'editor, modifica una lettera all'interno del testo dell'articolo nel file della cache e salva il file. Quindi quando aggiorni la pagina web dovresti vedere l'aggiornamento che hai fatto al file cache.

Come è possibile selezionare quali viste dei componenti vengono memorizzate nella cache e in quali circostanze? Ahimè, non puoi farlo. Ciò è determinato dagli sviluppatori del componente principale di Joomla e codificato nel codice php del componente. E i criteri sono diversi per ciascun componente. Tuttavia, puoi facilmente scoprire quali criteri vengono utilizzati perché per ciascuno dei componenti del sito sono codificati nel file controller.php del sito. Ad esempio, al momento della stesura (versione Joomla 3.9.2) per il componente contatti troviamo in components/com_contact / controller.php

if (JFactory::getApplication()->getUserState('com_contact.contact.data') === null)
{
	$cachable = true;
}

Questo significa che le viste associate ai contatti saranno accessibili a meno che non ci siano dati di sessione digitati da com_contact.contact.data - che sarà il caso se nella sessione utente l'utente ha visualizzato un modulo di contatto (ad esempio su una pagina indicata da un menuitem di tipo Contatti / Contatto singolo).

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.

Si può anche dimostrare che i moduli sono in cache utilizzando il modulo Joomla Breadcrumbs, assicurandosi che sia visualizzato in qualche posizione del modulo sulla pagina web, impostando la sua opzione Caching e modificando manualmente il file in cache/mod_breadcrumbs.

Progressive Caching

Come il Conservative Caching, anche il Progressive Caching memorizza l'output dalle viste dei componenti e dai moduli. La differenza funzionale tra i due è che con il Progressive Caching tutti i moduli sono sempre in cache. In questo caso, impostare l'opzione No caching per un modulo non ha alcun effetto. Se l'opzione caching storage è File allora si può trovare il file di cache dei moduli (l'output di tutti i moduli è memorizzato nello stesso file) all'interno della cartella cache/com_modules.

Per attivare la cache progressiva, passare all'amministratore Configurazione globale / Sistema e, all'interno delle impostazioni della cache, impostare la cache di sistema su ON - Cache progressiva.

Per quanto riguarda le condizioni per il caching di Joomla core component views non c'è differenza tra il caching conservativo e quello progressivo. Nonostante quello che si può leggere su alcuni siti web e le risposte alle domande di overflow stack, non è il caso che la cache conservativa si riferisce a quando l'utente non è connesso e la cache progressiva a quando l'utente è connesso.

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.

View Caching

  • Configuration: Global Config -> Cache
  • Caches: each view of a component
  • Based on: URL, view, parameters, ...
  • More info: Component developers have to include this in their code to work. Mostly this is not done. The Joomla main content component uses this, but only for guest visitors of your site though this is not obligated for every 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

Further 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 Engines or Storage

  • 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, for example, also caches your PHP opcode.

For Developers

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.

Don't forget that the first level of cache encountered, will override any deeper caching. I suppose that too many levels is also counterproductive (to be verified though).

  • JCacheView caches and returns the output of a given view (in MVC). A cache id is automatically generated from the URI, specific view and its specific method, or you can give your own.

This can automatically be done via the base controller's display function. For example in the controller of your component:

class DeliciousController extends JController {
	function display() {
		parent::display(true); //true asks for caching.
	}
}

There are also some urlparams to consider. Check this "joomla stack"

Also, be aware that any updates (such as hits or visit counts) will not be updated (unless you add this outside this method and thus any deeper MVC-part.)

  • JCachePage caches and returns the body of the page.
  • JCacheCallback caches and returns the output and results of functions or methods.

If you want to cache queries, this is a good class for it, as illustrated here: Using caching to speed up your code

  • JCacheOutput caches and returns output.

This is rather meant for caching a specific part of PHP code. It acts like an output buffer, but cached.

References