osCSS_Cache Class Reference

Class usage examples:. More...

List of all members.

Public Member Functions

Static Public Member Functions

  • static clear ($key, $core=false)

Protected Attributes

Static Protected Attributes

Static Private Member Functions

  • static write ($key, $data, $force=false)

Detailed Description

Class usage examples:.

Definition at line 32 of file osCSS_Cache.php.


Constructor & Destructor Documentation

osCSS_Cache::__construct (  ) 

Definition at line 41 of file osCSS_Cache.php.

00041                         {
00042     $this->cached_data=null;
00043     $this->cache_key=null;
00044     self::$_folder=(defined('DIR_WS_ADMIN')? DIR_FS_ADMIN.DIR_WS_INCLUDES.'tmp/cache/' : DIR_FS_WORK);
00045   }


Member Function Documentation

static osCSS_Cache::clear ( key,
core = false 
) [static]
Parameters:
$key string key base du nom des fichier a supprimer
$core bool core false = public, true = admin

Definition at line 118 of file osCSS_Cache.php.

00118                                                   {
00119     $key_length = strlen($key);
00120 
00121     $folder=(($core)? DIR_FS_ADMIN.DIR_WS_INCLUDES.'tmp/cache/' : DIR_FS_WORK);
00122 
00123     $d = dir($folder);
00124     if(is_object($d)){
00125       while ($entry = $d->read()) {
00126         if ((strlen($entry) >= $key_length) && (substr($entry, 0, $key_length) == $key)) {
00127           unlink($folder . $entry);
00128         }
00129       }
00130 
00131       $d->close();
00132     }
00133   }

osCSS_Cache::getCache (  ) 

Definition at line 91 of file osCSS_Cache.php.

00091                              {
00092     return $this->cached_data;
00093   }

osCSS_Cache::read ( key,
expire = 0,
force = false 
)

Definition at line 65 of file osCSS_Cache.php.

00065                                                         {
00066     self::$_instance = new self();
00067 
00068     if(!$force && OSCSS_DEBUG ===true) return false;
00069 
00070     $this->cache_key = $key;
00071 
00072     $filename = self::$_folder . $key . '.cache';
00073 
00074     if (file_exists($filename)) {
00075       $difference = floor((time() - filemtime($filename)) / 60);
00076 
00077       if ( ($expire == '0') || ($difference < $expire) ) {
00078         if ($fp = @fopen($filename, 'r')) {
00079           $this->cached_data = @unserialize(fread($fp, filesize($filename)));
00080 
00081           fclose($fp);
00082 
00083           return true;
00084         }
00085       }
00086     }
00087 
00088     return false;
00089   }

osCSS_Cache::startBuffer (  ) 

Definition at line 95 of file osCSS_Cache.php.

00095                                 {
00096     ob_start();
00097   }

osCSS_Cache::stopBuffer (  ) 

Definition at line 99 of file osCSS_Cache.php.

00099                                {
00100     $this->cached_data = ob_get_contents();
00101 
00102     ob_end_clean();
00103 
00104     self::write($this->cache_key, $this->cached_data);
00105     self::$_instance = null;
00106   }

static osCSS_Cache::write ( key,
data,
force = false 
) [static, private]

Definition at line 47 of file osCSS_Cache.php.

Referenced by stopBuffer(), and writeBuffer().

00047                                                            {
00048 
00049     if(!$force && OSCSS_DEBUG ===true) return false;
00050 
00051     $filename = self::$_folder . $key . '.cache';
00052 
00053     if ($fp = @fopen($filename, 'w')) {
00054       flock($fp, 2); // LOCK_EX
00055       fputs($fp, serialize($data));
00056       flock($fp, 3); // LOCK_UN
00057       fclose($fp);
00058 
00059       return true;
00060     }
00061 
00062     return false;
00063   }

osCSS_Cache::writeBuffer ( data,
force = false 
)

Definition at line 108 of file osCSS_Cache.php.

00108                                                    {
00109     $this->cached_data = $data;
00110 
00111     self::write($this->cache_key, $this->cached_data,$force);
00112   }


Member Data Documentation

osCSS_Cache::$_folder [static, protected]

Definition at line 39 of file osCSS_Cache.php.

osCSS_Cache::$_instance [static, protected]

Definition at line 37 of file osCSS_Cache.php.

osCSS_Cache::$cache_key [protected]

Definition at line 35 of file osCSS_Cache.php.

osCSS_Cache::$cached_data [protected]

Definition at line 33 of file osCSS_Cache.php.


The documentation for this class was generated from the following file: