Get Smarty

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:

Check reviews of PHP Web Hosting, compatible with Smarty Templates

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.
Post a Comment
All comments are moderated. Support questions are ignored, use the forums instead.
Author:
Email: (not shown)
What is 0 plus 20? (Are you human?)

Sponsors [info]

Cheap Website Hosting @hostdone.com
email marketing @ActiveCampaign
broadband deals @BroadbandGenie
Best UK Web Hosting @webhost.uk.net
Reliable UK and US Web Hosting @rshosting.com
Cheap US and UK Web Hosting @infrenion.com
I.T Certification Exams @pass-guaranteed.com
Certification Practice Tests @firsttrycertify.com
Certification Practice Exam Questions @ace-it-certifications.com
Broadband Speed Test @broadbandspeed.co.uk
bulk email software @americaint.com
ASP.NET hosting @aspnethosting.co.uk