Advertisement
Guest User

Untitled

a guest
Sep 5th, 2012
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.83 KB | None | 0 0
  1. <?php
  2.  
  3.  
  4.  
  5. /**
  6.  
  7.  * XCache class
  8.  
  9.  */
  10.  
  11. if (!defined('W3TC')) {
  12.  
  13.     die();
  14.  
  15. }
  16.  
  17.  
  18.  
  19. require_once W3TC_LIB_W3_DIR . '/Cache/Base.php';
  20.  
  21.  
  22.  
  23. /**
  24.  
  25.  * Class W3_Cache_Xcache
  26.  
  27.  */
  28.  
  29. class W3_Cache_Xcache extends W3_Cache_Base {
  30.  
  31.     /**
  32.  
  33.      * Adds data
  34.  
  35.      *
  36.  
  37.      * @param string $key
  38.  
  39.      * @param mixed $var
  40.  
  41.      * @param integer $expire
  42.  
  43.      * @return boolean
  44.  
  45.      */
  46.  
  47.     function add($key, &$var, $expire = 0) {
  48.  
  49.         if ($this->get($key) === false) {
  50.  
  51.             return $this->set($key, $var, $expire);
  52.  
  53.         }
  54.  
  55.  
  56.  
  57.         return false;
  58.  
  59.     }
  60.  
  61.  
  62.  
  63.     /**
  64.  
  65.      * Sets data
  66.  
  67.      *
  68.  
  69.      * @param string $key
  70.  
  71.      * @param mixed $var
  72.  
  73.      * @param integer $expire
  74.  
  75.      * @return boolean
  76.  
  77.      */
  78.  
  79.     function set($key, &$var, $expire = 0) {
  80.  
  81.         return xcache_set($key, serialize($var), $expire);
  82.  
  83.     }
  84.  
  85.  
  86.  
  87.     /**
  88.  
  89.      * Returns data
  90.  
  91.      *
  92.  
  93.      * @param string $key
  94.  
  95.      * @return mixed
  96.  
  97.      */
  98.  
  99.     function get($key) {
  100.  
  101.         return @unserialize(xcache_get($key));
  102.  
  103.     }
  104.  
  105.  
  106.  
  107.     /**
  108.  
  109.      * Replaces data
  110.  
  111.      *
  112.  
  113.      * @param string $key
  114.  
  115.      * @param mixed $var
  116.  
  117.      * @param integer $expire
  118.  
  119.      * @return boolean
  120.  
  121.      */
  122.  
  123.     function replace($key, &$var, $expire = 0) {
  124.  
  125.         if ($this->get($key) !== false) {
  126.  
  127.             return $this->set($key, $var, $expire);
  128.  
  129.         }
  130.  
  131.  
  132.  
  133.         return false;
  134.  
  135.     }
  136.  
  137.  
  138.  
  139.     /**
  140.  
  141.      * Deletes data
  142.  
  143.      *
  144.  
  145.      * @param string $key
  146.  
  147.      * @return boolean
  148.  
  149.      */
  150.  
  151.     function delete($key) {
  152.  
  153.         return xcache_unset($key);
  154.  
  155.     }
  156.  
  157.  
  158.  
  159.     /**
  160.  
  161.      * Flushes all data
  162.  
  163.      *
  164.  
  165.      * @return boolean
  166.  
  167.      */
  168.  
  169.     function flush() {
  170.  
  171.         xcache_clear_cache(XC_TYPE_VAR, 0);
  172.  
  173.  
  174.  
  175.         return true;
  176.  
  177.     }
  178.  
  179. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement