Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 18
Return Promise for set and remove#23
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Uh oh!
There was an error while loading. Please reload this page.
Conversation
src/ArrayCache.php Outdated
| publicfunctionset($key, $value) | ||
| { | ||
| $this->data[$key] = $value; | ||
| returnnewPromise\FulfilledPromise(true); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd prefer Promise\resolve(true) here.
src/ArrayCache.php Outdated
| publicfunctionremove($key) | ||
| { | ||
| unset($this->data[$key]); | ||
| returnnewPromise\FulfilledPromise(true); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd prefer Promise\resolve(true) here.
src/CacheInterface.php Outdated
| * @param string $key | ||
| * @param mixed $value | ||
| * @return void | ||
| * @return PromiseInterface<bool|Exception> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As discussed (ot sure where atm), only fulfillment values should be included.
PromiseInterface<bool>
src/CacheInterface.php Outdated
| * | ||
| * @param string $key | ||
| * @return void | ||
| * @return PromiseInterface<bool|Exception> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PromiseInterface<bool> (see above)
WyriHaximus commented Feb 20, 2018
@jsor addressed your points 👍 |
src/CacheInterface.php Outdated
| /** | ||
| * All methods only reject with an exception when an error occurs on the underlying storage | ||
| * layer, for example the connection with Redis dropped and cannot be recovered, or the | ||
| * directory on the filesystem used to store cache has the wrong permissions of is full. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
of is full -> or is full
WyriHaximus commented Feb 21, 2018
@jsor fixed 👍 |
clue left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No objections, but one question:
What is an "error" and how is this related to #22? It's my understanding that we aim for a Promise-based alternative interface similar to PSR-16, which uses the following return type for set():
@return bool True on success and false on failure.
@throws \Psr\SimpleCache\InvalidArgumentException MUST be thrown if the $key string is not a legal value.
jsor commented Feb 26, 2018
Good point, there was also a discussion here: https://github.com/reactphp/cache/pull/16/files#r104752102 |
WyriHaximus commented Feb 27, 2018
jsor commented Feb 28, 2018
Regarding
But since i've not attended the call, i'm probably missing something. |
WyriHaximus commented Feb 28, 2018
jsor commented Feb 28, 2018
The point is, that according to PSR-16, Refs: |
WyriHaximus commented Feb 28, 2018
clue commented Mar 13, 2018
We've discussed this only briefly in our last hangouts. My point is: I can see some valid arguments for both directions as rightfully pointed out by @jsor. I personally don't have a use case that requires any specific behavior, I only require consistent behavior. For now, I would vote to keep this in line with PSR-16 and simply use a promise with a boolean resolution value and basically never reject. I would rather get this feature out and we can still discuss this for a future version |
WyriHaximus commented Mar 24, 2018
src/CacheInterface.php Outdated
| * Retrieve an item from the cache, resolves with its value on | ||
| * success or null when no item can be found. | ||
| * success or null when no item can be found. It will reject with an exception | ||
| * on error. (Note that a cache miss isn't an error.) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rejecting would be the async equivalent of an Exception and I don't see this in PSR-16?
src/CacheInterface.php Outdated
| * All methods only reject with an exception when an error occurs on the underlying storage | ||
| * layer, for example the connection with Redis dropped and cannot be recovered, or the | ||
| * directory on the filesystem used to store cache has the wrong permissions or is full. | ||
| */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure if this is a leftover, but this seems to contradict the below definitions?
src/CacheInterface.php Outdated
| * @param string $key | ||
| * @param mixed $value | ||
| * @return void | ||
| * @return PromiseInterface<bool> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't see any notation for this in any of the major projects, so I would suggest using the more verbose form @return PromiseInterface Returns a promise which resolves to true on success of false on error and possibly update the description above? (See also below)
WyriHaximus commented Mar 25, 2018
@clue updated the cache interface 👍 |
README.md Outdated
| If the key `foo` does not exist, the promise will be fulfilled with `null` as value. | ||
| If the key `foo` does not exist, the promise will be fulfilled with `null` as value. On | ||
| any error it will reject with an exception. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
leftover?
WyriHaximus commented Mar 25, 2018
@clue whoops updated |
clue left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, please squash this to a reasonable number of commits before merging ![]()
WyriHaximus commented Mar 25, 2018
When @jsor also doesn't find any issues and approves I'll squash everything 👍 |
README.md Outdated
| already exists, it is overridden. No guarantees are made as to when the cache | ||
| value is set. If the cache implementation has to go over the network to store | ||
| already exists, it is overridden. To provide guarantees as to when the cache | ||
| value is set a promise is returned. Which will fulfill with `true` on success or |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should either be one sentence ("...a promise is returned which will fulfill...") or better separated ("...a promise is returned. The promise will fulfill...").
WyriHaximus commented Mar 26, 2018
@jsor done |
a814de4 to 584e3c2CompareWyriHaximus commented Mar 26, 2018
Squashed the commits, the whole history without the squash is available here: https://github.com/WyriHaximus-labs/cache/tree/return_promises_history |
This PR builds on #16 by resolving merge conflicts and adding more documentation in the cache interface plus adding documentation to the readme.
Supersedes / closes#16