[ Index ]
 

Code source de LifeType 1.2.4

Accédez au Source d'autres logiciels libres

Classes | Fonctions | Variables | Constantes | Tables

title

Body

[fermer]

/class/template/ -> cachecontrol.class.php (source)

   1  <?php
   2  
   3      /**
   4       * \ingroup Template
   5       * 
   6       * Allows to control Smarty's caches in an easier way. You can call any of these methods
   7       * whenever you need to clear the contents of the whole site, the summary or just a single
   8       * blog.
   9       */
  10      class CacheControl 
  11      {
  12  
  13          /**
  14           * resets all the caches in the site
  15           * @static
  16           * @return Always true
  17           */
  18  		function resetAllCaches()
  19          {
  20              // get a list of all the blogs
  21              lt_include( PLOG_CLASS_PATH."class/dao/blogs.class.php" );
  22              $blogs = new Blogs();
  23              $siteBlogs = $blogs->getAllBlogIds();
  24              
  25              // and loop through them
  26              foreach( $siteBlogs as $blogId ) {
  27                  CacheControl::resetBlogCache( $blogId, false );
  28              }
  29              
  30              // clear the cache used by the summary
  31              CacheControl::clearSummaryCache();
  32  
  33              return true;
  34          }
  35          
  36          /**
  37           * clears the cache of the summary, since it is also allowed to use it :)
  38           * This method is also used when using CacheControl::resetAllCaches()
  39           *
  40           * @see resetAllCaches
  41           * @static
  42           */
  43  		function clearSummaryCache()
  44          {
  45              $config =& Config::getConfig();
  46              // nothing to do if caching is not enabled...
  47              if( !$config->getValue( "template_cache_enabled" ))
  48                  return false;            
  49                  
  50              // nothing to do either if the summary page lifetime is greater than 0,
  51              // since smarty will take care of resetting it when needed
  52              $summaryTemplateLifetime = $config->getValue( "summary_template_cache_lifetime" );
  53              if( $summaryTemplateLifetime > 0 )
  54                  return true;
  55                  
  56              // if not then continue...
  57              lt_include( PLOG_CLASS_PATH."class/template/cachedtemplate.class.php" );            
  58              $t = new CachedTemplate( null );            
  59              $tmpFolder = $config->getValue( "temp_folder" );
  60              $summaryTmpFolder = $tmpFolder."/summary";
  61              
  62              // delete the contents of the folder, but not its structure or subfolders
  63              File::deleteDir( $summaryTmpFolder, true, true );
  64              
  65              return true;        
  66          }
  67          
  68          /**
  69           * alias for clearSummaryCache
  70           * @see clearSummaryCache
  71           * @static         
  72           */
  73  		function resetSummaryCache()
  74          {
  75              return CacheControl::clearSummaryCache();
  76          }
  77  
  78          /**
  79           * resets the cache of a blog
  80           *
  81           * @param blogId The id of the blog whose cache we'd like to reset
  82           * @param resetSummary whether the summary cache should also be cleaned up,
  83           * enabled by default
  84           * @static         
  85           */
  86  		function resetBlogCache( $blogId, $resetSummary = true )
  87          {
  88              $config =& Config::getConfig();
  89              // nothing to do if caching is not enabled...
  90              if( !$config->getValue( "template_cache_enabled" ))
  91                  return false;
  92          
  93              $tmpFolder = $config->getValue( "temp_folder" );
  94              $blogTmpFolder = $tmpFolder."/".$blogId;
  95  
  96              // recursively delete the contents of the folder, but not its structure or subfolders            
  97              File::deleteDir( $blogTmpFolder, true, true );
  98              
  99              //$t->clear_cache( null );
 100              
 101              // we need to clear the contents of the summary caches because we have added or removed
 102              // posts or done something that might affect the summary!
 103              if( $resetSummary )
 104                  CacheControl::clearSummaryCache();
 105              
 106              return true;
 107          }
 108      }
 109  ?>


Généré le : Mon Nov 26 21:04:15 2007 par Balluche grâce à PHPXref 0.7
  Clicky Web Analytics