Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Adding delete method per issues #3 and #6 - can only handle one key a…

…t a time at the moment
  • Loading branch information...
commit fc9887a0ae755041b4855d48f93a584f2958cf34 1 parent 035570a
@beryllium authored
View
17 Cache.php
@@ -106,6 +106,23 @@ public function set( $key, $value, $ttl = 300 )
return false;
}
+ /**
+ * Delete a key from the cache
+ *
+ * @param string $key Unique key
+ * @access public
+ * @return void
+ */
+ public function delete( $key )
+ {
+ if ( $this->isSafe() && !empty( $key ) )
+ {
+ return $this->client->delete( $key );
+ }
+
+ return false;
+ }
+
/**
* Checks if the cache is in a usable state
*
View
9 CacheClientInterface.php
@@ -32,6 +32,15 @@ public function get( $key );
*/
public function set( $key, $value, $ttl );
+ /**
+ * Delete a value from the cache
+ *
+ * @param string $key
+ * @access public
+ * @return void
+ */
+ public function delete( $key );
+
/**
* Check the state of the cache
*
View
1  CacheInterface.php
@@ -17,5 +17,6 @@
public function __construct( CacheClientInterface $client = null );
public function get( $key );
public function set( $key, $value, $ttl );
+ public function delete( $key );
public function isSafe();
}
View
10 Client/FilecacheClient.php
@@ -93,6 +93,16 @@ public function set( $key, $value, $ttl = 300 )
}
}
+ public function delete( $key )
+ {
+ $filename = $this->buildFilename( $key );
+
+ if ( file_exists( $filename ) )
+ {
+ unlink( $filename );
+ }
+ }
+
public function setPath( $path )
{
if ( !empty( $path ) && is_dir( $path ) && is_writable( $path ) )
View
19 Client/MemcacheClient.php
@@ -160,6 +160,25 @@ public function set( $key, $value, $ttl )
}
}
+ /**
+ * Delete a value from the memcache
+ *
+ * @param string $key Unique key
+ * @access public
+ * @return void
+ */
+ public function delete( $key )
+ {
+ if ( $this->isSafe() )
+ {
+ return $this->mem->delete( $key, 0 );
+ }
+ else
+ {
+ return false;
+ }
+ }
+
/**
* Check if the cache is live
*
Please sign in to comment.
Something went wrong with that request. Please try again.