CacheSegmentHandler.class.php

Go to the documentation of this file.
00001 <?php
00002 /***************************************************************************
00003  *   Copyright (C) 2007 by Konstantin V. Arkhipov                          *
00004  *                                                                         *
00005  *   This program is free software; you can redistribute it and/or modify  *
00006  *   it under the terms of the GNU Lesser General Public License as        *
00007  *   published by the Free Software Foundation; either version 3 of the    *
00008  *   License, or (at your option) any later version.                       *
00009  *                                                                         *
00010  ***************************************************************************/
00011 
00015     final class CacheSegmentHandler implements SegmentHandler
00016     {
00017         private $index = null;
00018         
00019         public function __construct($segmentId)
00020         {
00021             $this->index = $segmentId;
00022         }
00023         
00024         public function touch($key)
00025         {
00026             if (!Cache::me()->append($this->index, $key)) {
00027                 return
00028                     Cache::me()->set(
00029                         $this->index,
00030                         '|'.$key,
00031                         Cache::EXPIRES_FOREVER
00032                     );
00033             }
00034             
00035             return true;
00036         }
00037         
00038         public function unlink($key)
00039         {
00040             if ($data = Cache::me()->get($this->index)) {
00041                 return
00042                     Cache::me()->set(
00043                         $this->index,
00044                         str_replace('|'.$key, null, $data),
00045                         Cache::EXPIRES_FOREVER
00046                     );
00047             }
00048             
00049             return false;
00050         }
00051         
00052         public function ping($key)
00053         {
00054             if ($data = Cache::me()->get($this->index)) {
00055                 return (strpos($data, '|'.$key) !== false);
00056             }
00057             
00058             return false;
00059         }
00060         
00061         public function drop()
00062         {
00063             return Cache::me()->delete($this->index);
00064         }
00065     }
00066 ?>