Skip to content

Conversation

@WyriHaximus
Copy link
Member

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

public function set($key, $value)
{
$this->data[$key] = $value;
return new Promise\FulfilledPromise(true);
Copy link
Member

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.

public function remove($key)
{
unset($this->data[$key]);
return new Promise\FulfilledPromise(true);
Copy link
Member

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.

* @param string $key
* @param mixed $value
* @return void
* @return PromiseInterface<bool|Exception>
Copy link
Member

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>

*
* @param string $key
* @return void
* @return PromiseInterface<bool|Exception>
Copy link
Member

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
Copy link
Member Author

@jsor addressed your points 👍

/**
* 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.
Copy link
Member

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 added a commit to WyriHaximus-labs/cache that referenced this pull request Feb 21, 2018
@WyriHaximus
Copy link
Member Author

@jsor fixed 👍

Copy link
Member

@clue clue left a 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
Copy link
Member

jsor commented Feb 26, 2018

Good point, there was also a discussion here: https://github.com/reactphp/cache/pull/16/files#r104752102

@WyriHaximus
Copy link
Member Author

@jsor @clue updated PR with the points discussed during our call

@jsor
Copy link
Member

jsor commented Feb 28, 2018

Regarding set() now returning null: That differs now from PSR-16. As @clued noted in #23 (review):

@return bool True on success and false on failure.

But since i've not attended the call, i'm probably missing something.

@WyriHaximus
Copy link
Member Author

@jsor right so the thing @clue and I discussed is that when it always resolves true on success or rejects with an error we might as well resolve with null because true doesn't add any value.

@jsor
Copy link
Member

jsor commented Feb 28, 2018

The point is, that according to PSR-16, set() never throws, except for an invalid key. That means, our promise only rejects for an invalid key and resolves to true/false otherwise.

Refs:

@WyriHaximus
Copy link
Member Author

@jsor that makes sense so we should always resolve with true on success false on failure. That will mean the use won't get any exceptions but the cache implementation should handle/log those them self. Makes perfect sense to me. What do you think @clue ?

@clue
Copy link
Member

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 :shipit:

@WyriHaximus
Copy link
Member Author

Ping @jsor && @clue updated the PR

* 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.)
Copy link
Member

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?

* 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.
*/
Copy link
Member

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?

* @param string $key
* @param mixed $value
* @return void
* @return PromiseInterface<bool>
Copy link
Member

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
Copy link
Member Author

@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.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

leftover?

@WyriHaximus
Copy link
Member Author

@clue whoops updated

Copy link
Member

@clue clue left a 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 :shipit:

@clue clue added BC break and removed help wanted labels Mar 25, 2018
@WyriHaximus
Copy link
Member Author

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
Copy link
Member

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
Copy link
Member Author

@jsor done

WyriHaximus added a commit to WyriHaximus-labs/cache that referenced this pull request Mar 26, 2018
@WyriHaximus
Copy link
Member Author

Squashed the commits, the whole history without the squash is available here: https://github.com/WyriHaximus-labs/cache/tree/return_promises_history

@WyriHaximus WyriHaximus merged commit 9478319 into reactphp:master Mar 26, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants