Skip to content

Commit 7dcf881

Browse files
authored
Merge pull request #6 from matthiasmullie/master
Update reflecting suggestions since opening final review
2 parents 13f43ba + 30b9928 commit 7dcf881

File tree

4 files changed

+78
-59
lines changed

4 files changed

+78
-59
lines changed

src/CacheException.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
3+
namespace Psr\SimpleCache;
4+
5+
/**
6+
* Interface used for all types of exceptions thrown by the implementing library.
7+
*/
8+
interface CacheException
9+
{
10+
}

src/CacheInterface.php

Lines changed: 55 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -5,84 +5,110 @@
55
interface CacheInterface
66
{
77
/**
8-
* Fetch a value from the cache.
8+
* Fetches a value from the cache.
99
*
10-
* @param string $key The unique key of this item in the cache
11-
* @param mixed $default Default value to return if the key does not exist
10+
* @param string $key The unique key of this item in the cache.
11+
* @param mixed $default Default value to return if the key does not exist.
1212
*
13-
* @return mixed The value of the item from the cache, or $default in case of cache miss
13+
* @return mixed The value of the item from the cache, or $default in case of cache miss.
14+
*
15+
* @throws \Psr\SimpleCache\InvalidArgumentException
16+
* MUST be thrown if the $key string is not a legal value.
1417
*/
1518
public function get($key, $default = null);
1619

1720
/**
18-
* Persist data in the cache, uniquely referenced by a key with an optional expiration TTL time.
21+
* Persists data in the cache, uniquely referenced by a key with an optional expiration TTL time.
1922
*
20-
* @param string $key The key of the item to store
21-
* @param mixed $value The value of the item to store
23+
* @param string $key The key of the item to store.
24+
* @param mixed $value The value of the item to store, must be serializable.
2225
* @param null|int|DateInterval $ttl Optional. The TTL value of this item. If no value is sent and
2326
* the driver supports TTL then the library may set a default value
2427
* for it or let the driver take care of that.
2528
*
26-
* @return bool True on success and false on failure
29+
* @return bool True on success and false on failure.
30+
*
31+
* @throws \Psr\SimpleCache\InvalidArgumentException
32+
* MUST be thrown if the $key string is not a legal value.
2733
*/
2834
public function set($key, $value, $ttl = null);
2935

3036
/**
31-
* Delete an item from the cache by its unique key
37+
* Delete an item from the cache by its unique key.
38+
*
39+
* @param string $key The unique cache key of the item to delete.
3240
*
33-
* @param string $key The unique cache key of the item to delete
41+
* @return bool True if the item was successfully removed. False if there was an error.
3442
*
35-
* @return void
43+
* @throws \Psr\SimpleCache\InvalidArgumentException
44+
* MUST be thrown if the $key string is not a legal value.
3645
*/
3746
public function delete($key);
3847

3948
/**
40-
* Wipe clean the entire cache's keys
49+
* Wipes clean the entire cache's keys.
4150
*
42-
* @return void
51+
* @return bool True on success and false on failure.
4352
*/
4453
public function clear();
4554

4655
/**
47-
* Obtain multiple cache items by their unique keys
56+
* Obtains multiple cache items by their unique keys.
4857
*
49-
* @param array|Traversable $keys A list of keys that can obtained in a single operation.
58+
* @param array|\Traversable $keys A list of keys that can obtained in a single operation.
59+
* @param mixed $default Default value to return for keys that do not exist.
5060
*
51-
* @return array An array of key => value pairs. Cache keys that do not exist or are stale will have a value of null.
61+
* @return array|\Traversable A list of key => value pairs. Cache keys that do not exist or are stale will have $default as value.
62+
*
63+
* @throws \Psr\SimpleCache\InvalidArgumentException
64+
* MUST be thrown if $keys is neither an array nor a Traversable,
65+
* or if any of the $keys are not a legal value.
5266
*/
53-
public function getMultiple($keys);
67+
public function getMultiple($keys, $default = null);
5468

5569
/**
56-
* Persisting a set of key => value pairs in the cache, with an optional TTL.
70+
* Persists a set of key => value pairs in the cache, with an optional TTL.
5771
*
58-
* @param array|Traversable $items An array of key => value pairs for a multiple-set operation.
59-
* @param null|int|DateInterval $ttl Optional. The TTL value of this item. If no value is sent and
60-
* the driver supports TTL then the library may set a default value
61-
* for it or let the driver take care of that.
72+
* @param array|\Traversable $values A list of key => value pairs for a multiple-set operation.
73+
* @param null|int|DateInterval $ttl Optional. The TTL value of this item. If no value is sent and
74+
* the driver supports TTL then the library may set a default value
75+
* for it or let the driver take care of that.
76+
*
77+
* @return bool True on success and false on failure.
6278
*
63-
* @return bool True on success and false on failure
79+
* @throws \Psr\SimpleCache\InvalidArgumentException
80+
* MUST be thrown if $values is neither an array nor a Traversable,
81+
* or if any of the $values are not a legal value.
6482
*/
65-
public function setMultiple($items, $ttl = null);
83+
public function setMultiple($values, $ttl = null);
6684

6785
/**
68-
* Delete multiple cache items in a single operation
86+
* Deletes multiple cache items in a single operation.
87+
*
88+
* @param array|\Traversable $keys A list of string-based keys to be deleted.
6989
*
70-
* @param array|Traversable $keys The array of string-based keys to be deleted
90+
* @return bool True if the item was successfully removed. False if there was an error.
7191
*
72-
* @return void
92+
* @throws \Psr\SimpleCache\InvalidArgumentException
93+
* MUST be thrown if $keys is neither an array nor a Traversable,
94+
* or if any of the $keys are not a legal value.
7395
*/
7496
public function deleteMultiple($keys);
7597

7698
/**
77-
* Identify if an item is in the cache.
99+
* Determines whether an item is present in the cache.
100+
*
78101
* NOTE: It is recommended that has() is only to be used for cache warming type purposes
79102
* and not to be used within your live applications operations for get/set, as this method
80103
* is subject to a race condition where your has() will return true and immediately after,
81104
* another script can remove it making the state of your app out of date.
82105
*
83-
* @param string $key The cache item key
106+
* @param string $key The cache item key.
84107
*
85108
* @return bool
109+
*
110+
* @throws \Psr\SimpleCache\InvalidArgumentException
111+
* MUST be thrown if the $key string is not a legal value.
86112
*/
87113
public function has($key);
88114
}

src/CounterInterface.php

Lines changed: 0 additions & 30 deletions
This file was deleted.

src/InvalidArgumentException.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
namespace Psr\SimpleCache;
4+
5+
/**
6+
* Exception interface for invalid cache arguments.
7+
*
8+
* When an invalid argument is passed it must throw an exception which implements
9+
* this interface
10+
*/
11+
interface InvalidArgumentException extends CacheException
12+
{
13+
}

0 commit comments

Comments
 (0)