library/SimplePie/Cache/Memcache.php Quellcode

Memcache.php
gehe zur Dokumentation dieser Datei
1 <?php
59 {
65  protected $cache;
66 
72  protected $options;
73 
79  protected $name;
80 
88  public function __construct($location, $name, $type)
89  {
90  $this->options = array(
91  'host' => '127.0.0.1',
92  'port' => 11211,
93  'extras' => array(
94  'timeout' => 3600, // one hour
95  'prefix' => 'simplepie_',
96  ),
97  );
98  $parsed = SimplePie_Cache::parse_URL($location);
99  $this->options['host'] = empty($parsed['host']) ? $this->options['host'] : $parsed['host'];
100  $this->options['port'] = empty($parsed['port']) ? $this->options['port'] : $parsed['port'];
101  $this->options['extras'] = array_merge($this->options['extras'], $parsed['extras']);
102  $this->name = $this->options['extras']['prefix'] . md5("$name:$type");
103 
104  $this->cache = new Memcache();
105  $this->cache->addServer($this->options['host'], (int) $this->options['port']);
106  }
107 
114  public function save($data)
115  {
116  if ($data instanceof SimplePie)
117  {
118  $data = $data->data;
119  }
120  return $this->cache->set($this->name, serialize($data), MEMCACHE_COMPRESSED, (int) $this->options['extras']['timeout']);
121  }
122 
128  public function load()
129  {
130  $data = $this->cache->get($this->name);
131 
132  if ($data !== false)
133  {
134  return unserialize($data);
135  }
136  return false;
137  }
138 
144  public function mtime()
145  {
146  $data = $this->cache->get($this->name);
147 
148  if ($data !== false)
149  {
150  // essentially ignore the mtime because Memcache expires on it's own
151  return time();
152  }
153 
154  return false;
155  }
156 
162  public function touch()
163  {
164  $data = $this->cache->get($this->name);
165 
166  if ($data !== false)
167  {
168  return $this->cache->set($this->name, $data, MEMCACHE_COMPRESSED, (int) $this->duration);
169  }
170 
171  return false;
172  }
173 
179  public function unlink()
180  {
181  return $this->cache->delete($this->name, 0);
182  }
183 }




Korrekturen, Hinweise und Ergänzungen

Bitte scheuen Sie sich nicht und melden Sie, was auf dieser Seite sachlich falsch oder irreführend ist, was ergänzt werden sollte, was fehlt usw. Dazu bitte oben aus dem Menü Seite den Eintrag Support Forum wählen. Es ist eine kostenlose Anmeldung erforderlich, um Anmerkungen zu posten. Unpassende Postings, Spam usw. werden kommentarlos entfernt.