Jelajahi Sumber

add DeleteLock

Brad Fitzpatrick 14 tahun lalu
induk
melakukan
f75c32ecbd
1 mengubah file dengan 11 tambahan dan 1 penghapusan
  1. 11 1
      memcache/memcache.go

+ 11 - 1
memcache/memcache.go

@@ -426,8 +426,18 @@ func writeExpectf(rw *bufio.ReadWriter, expect []byte, format string, args ...in
 	return fmt.Errorf("memcache: unexpected response line: %q", string(line))
 	return fmt.Errorf("memcache: unexpected response line: %q", string(line))
 }
 }
 
 
+// Delete deletes the item with the provided key. The error ErrCacheMiss is
+// returned if the item didn't already exist in the cache.
 func (c *Client) Delete(key string) os.Error {
 func (c *Client) Delete(key string) os.Error {
+	return c.DeleteLock(key, 0)
+}
+
+// Delete deletes the item with the provided key, also instructing the
+// server to not permit an "add" or "replace" commands to work on the
+// key for the given duration (in seconds). The error ErrCacheMiss is
+// returned if the item didn't already exist in the cache.
+func (c *Client) DeleteLock(key string, seconds int) os.Error {
 	return c.withKeyRw(key, func(rw *bufio.ReadWriter) os.Error {
 	return c.withKeyRw(key, func(rw *bufio.ReadWriter) os.Error {
-		return writeExpectf(rw, resultDeleted, "delete %s\r\n", key)
+		return writeExpectf(rw, resultDeleted, "delete %s %d\r\n", key, seconds)
 	})
 	})
 }
 }