Skip to content
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

Feature/psr16 support #791

Merged
merged 11 commits into from
May 15, 2020
Merged

Feature/psr16 support #791

merged 11 commits into from
May 15, 2020

Conversation

jbout
Copy link
Contributor

@jbout jbout commented May 12, 2020

Support for SimpleCache implementations in the context of the cached functional access control

@jbout jbout requested a review from hutnikau May 12, 2020 14:42
/**
* Wrap the PSR simple cache implementation into the legacy interface
*/
class common_cache_PsrWrapperCache extends ConfigurableService implements common_cache_Cache
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's not create new classes in legacy namespace

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This class provides the legacy interface and should be discouraged from being used, as is present for backward compatibility only.

Copy link
Contributor

@hutnikau hutnikau May 13, 2020

Choose a reason for hiding this comment

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

should be discouraged from being used

In that case it has to be marked as deprecated.
As we are going to get rid of legacy autoloader it's better to not create new classes in the legacy namespace

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

Copy link
Contributor

Choose a reason for hiding this comment

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

Introduce in the PR a new deprecated class and then configure it to be used by default does not seem to me like a good practice!

How difficult will be to change it's usage to not catch common_cache_NotFoundException? I found 14 catches of that exception in three extensions:
tao
taoAct
taoMpArt (that one can be omitted)

I could help with cleaning that up.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I removed all references to old cache from generis, so that we can move quicker when it comes to cleaning up old references, but I still don't want to make this feature backward incompatible, even if we could fix all other known extensions quickly

{
$success = true;
foreach ($values as $key => $value) {
$success = $this->set($key, $value, $ttl) && $success;
Copy link
Contributor

Choose a reason for hiding this comment

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

It may confuse developers. In case of failure all already set values have to be deleted.
The same for delete. All already deleted items have to be restored.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I could not find any indication in the PSR on how a partial success/failure should be handled

Copy link
Contributor

Choose a reason for hiding this comment

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

In that case this behavior is up to implementation.
I think rolling back in that case corresponds to best practices.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Unfortunately I have no idea how to implement this rollback as filesystems are not transactional

@hutnikau
Copy link
Contributor

I don't like approach as it allows developers to use old cache interface.
I would extend existing interface with Psr\SimpleCache\CacheInterface and deprecate legacy methods.

@jbout
Copy link
Contributor Author

jbout commented May 13, 2020

Unfortunately our legacy get() method is not compatible with the PSR interface, so having dual support would not be possible

@hutnikau
Copy link
Contributor

hutnikau commented May 13, 2020

Unfortunately our legacy get() method is not compatible with the PSR interface, so having dual support would not be possible

Signature of get() method is compatible:
common_cache_Cache:

public function get($serial);

PSR-16:

public function get($key, $default = null);

Just add $default parameter to common_cache_Cache. It will not have impact on existing code

@jbout
Copy link
Contributor Author

jbout commented May 13, 2020

Our current implementation of get() throws an exception on cache miss, the PSR implementation returns the default value, so unfortunately this is not possible

@hutnikau
Copy link
Contributor

Throwing an exception when default value was not given does not seem like an interface violation.
The benefit here is that we will be able to gradually to move to PSR-16 implementation.

@hutnikau
Copy link
Contributor

Looks good!
Lets deprecate common_cache_Cache ?

@hutnikau
Copy link
Contributor

Please fix phpdoc block (@author and @access tags) and do you think it's possible to address issues found by codeclimate?

@jbout
Copy link
Contributor Author

jbout commented May 14, 2020

I could fix the issues, but it is in code that is going to be deleted, so I did not bother. Are there incorecct tags in the part of the code that will not be deleted?

Copy link
Contributor

@siwane siwane left a comment

Choose a reason for hiding this comment

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

Nice job, one step more to standardization. Could u create a task to remove this deprecated wrapper in order to close this topic ? :)

@siwane siwane merged commit 2739577 into develop May 15, 2020
@siwane siwane deleted the feature/psr16-support branch May 15, 2020 14:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants