Get Smarty

Donate

Paypal

Smarty Icon

You may use the Smarty logo according to the trademark notice.

Smarty Template Engine Smarty Template Engine

For sponsorship, advertising, news or other inquiries, contact us at:

Sites Using Smarty

Advertisement

Name

is_cached

bool is_cached(string template,
               string cache_id,
               string compile_id);

Restituisce TRUE se è presente una cache valida per questo template. Funziona soltanto se caching è impostato a true.

Example 13.18. is_cached


<?php
$smarty->caching = true;

if(!$smarty->is_cached("index.tpl")) {
// faccio le chiamate al database, assegno le variabili
}

$smarty->display("index.tpl");
?>

   

Potete passare anche una cache id come secondo parametro opzionale, nel caso vogliate cache multiple per il template dato.

Potete fornire un compile id come terzo parametro opzionale. Se lo omettete, viene usato il valore della variabile persistente $compile_id.

Se non volete passare una cache id ma volete passare un compile id dovete passare null come cache id.

Example 13.19. is_cached con template a cache multiple


<?php
$smarty->caching = true;

if(!$smarty->is_cached("index.tpl", "FrontPage")) {
  // faccio le chiamate al database, assegno le variabili
}

$smarty->display("index.tpl", "FrontPage");
?>

   

Nota tecnica

Se is_cached restituisce true, in realtà carica l'output in cache e lo memorizza internamente. Ogni chiamata successiva a display() o a fetch() restituirà questo output memorizzato internamente, e non cercherà di ricaricare il file della cache. Questo evita una situazione che potrebbe verificarsi quando un secondo processo elimina la cache nell'intervallo fra la chiamata a is_cached e quella a display, nell'esempio visto prima. Questo significa anche che le chiamate a clear_cache() ed altre modifiche fatte sulle impostazioni della cache potrebbero non avere effetto dopo che is_cached ha restituito true.

Comments
No comments for this page.

Advertisement

Sponsors [info]

Sponsors