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

feat: initial commit to move laravel-cache to momentohq #1

Merged
merged 19 commits into from
Nov 7, 2022

Conversation

poppoerika
Copy link
Collaborator

Moved all the files from my personal repo.

Relevant ticket: https://github.com/momentohq/dev-eco-issue-tracker/issues/126

@poppoerika
Copy link
Collaborator Author

@cprice404 @pgautier404
I don't have admin rights to I'm not sure how other repos are set up in terms of rules.
If you can add these on the settings, that would be appreciated. Or, if you can let me know, I can do that as well 🙇‍♀️

README.md Outdated
Comment on lines 40 to 44
{
"require": {
"momentohq/laravel-momento-cache": "0.0.1"
}
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
{
"require": {
"momentohq/laravel-momento-cache": "0.0.1"
}
}
{
"repositories": [
{
"type": "vcs",
"url": "https://github.com/momentohq/laravel-cache"
}
],
"require": {
"momentohq/laravel-cache": "0.0.1"
}
}

README.md Outdated
"repositories": [
{
"type": "vcs",
"url": "https://github.com/momentohq/client-sdk-php"
Copy link
Collaborator

@pgautier404 pgautier404 Nov 3, 2022

Choose a reason for hiding this comment

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

The repository here needs to match the require below it:

Suggested change
"url": "https://github.com/momentohq/client-sdk-php"
"url": "https://github.com/momentohq/laravel-cache"

Copy link
Contributor

@cprice404 cprice404 left a comment

Choose a reason for hiding this comment

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

looking really good! sorry it took me so long to review.

README.md Outdated
<head>
<meta name="Momento Laravel cache driver" content="Taggable Momento serverless cache driver for Laravel">
</head>
<img src="https://docs.momentohq.com/img/logo.svg" alt="logo" width="400"/>
Copy link
Contributor

Choose a reason for hiding this comment

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

we should be able to use the README generator for this. As long as you set the "type" to "other" then it won't require all of the sections that an SDK README requires, but you will get all of the header and badge stuff w/o having to manage it by hand.

README.md Outdated
],
// ...
],
```
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we need to add a section about the support for tags here. Specifically, if a tag may contain more than ~4MB worth of keys, tagging may not work properly. If the user needs support for a larger tag set, reach out to us via support@momentohq.com or our discord and we can do some work to make it more flexible.

public function flush()
{
throw new UnknownError("flush operations is currently not supported.");
}
Copy link
Contributor

Choose a reason for hiding this comment

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

We probably need to record this list of unsupported operations in the README as well.


public function increment($key, $value = 1)
{
return false;
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is this one returning false instead of erroring like the others?

Also, I wonder if we should go ahead and do a client-side implementation for putMany, increment, and decrement for now. We might want to have a zoom to discuss this.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It looks like increment is used when RouteServiceProvider is booting up in the weather app. So an error is thrown, I was not able to start the app.

Copy link
Contributor

Choose a reason for hiding this comment

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

okay then in that case let's do a client side implementation of this, where you read the key, if it doesn't exist set it to 0, then increment it, then save it.


public function forget($key)
{
throw new UnknownError("forget operations is currently not supported.");
Copy link
Contributor

Choose a reason for hiding this comment

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

I believe that we can implement this one today?


use Illuminate\Support\ServiceProvider;

class MomentoServiceProvider extends ServiceProvider
Copy link
Contributor

Choose a reason for hiding this comment

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

can you please create a ticket on the dev eco board to remind us to try to PR this directly into laravel once we have added the official support for increment/decrement/putMany in the future?

{
$tags = $this->tags->getNames();
$cacheName = $this->store->getCacheName();
$value = "erika";
Copy link
Contributor

Choose a reason for hiding this comment

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

?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yup. I noticed that too. I will update it 🙇‍♀️

}
return $value;
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

is there any way to add a few simple integration tests to this repo?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I wanted to add it in a follow-up PR if it's okay.

@cprice404
Copy link
Contributor

@cprice404 @pgautier404 I don't have admin rights to I'm not sure how other repos are set up in terms of rules. If you can add these on the settings, that would be appreciated. Or, if you can let me know, I can do that as well 🙇‍♀️

I added the branch protection rules for main. Thanks for the heads up. If we see anything else missing I can update further.

Copy link
Contributor

@cprice404 cprice404 left a comment

Choose a reason for hiding this comment

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

i left a few nits for readme/github actions but if you prefer to merge and then do those in a follow-up that's okay. Also just verifying that you are planning to add some tests in a follow-up?

project_status: official
project_stability: alpha
project_type: other
sdk_language: PHP
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: I don't think this field gets used for non-SDK artifacts. Might be more clear to remove it.

steps:
- uses: actions/checkout@v3

- name: Verify README generation
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think we want to do readme generation on the release step, I think you can remove this.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This step is for verifying a generated README in the push to main, so we want to keep this to make sure the generated README is valid and follows the required rules? (Our PHP SDK has this step for the on-push-to-release workflow as well)

Copy link
Contributor

Choose a reason for hiding this comment

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

okay

"repositories": [
{
"type": "vcs",
"url": "https://github.com/momentohq/laravel-cache"
Copy link
Contributor

Choose a reason for hiding this comment

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

will these be the correct directions for pulling from our release branch?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

My understanding is that we specify which version/branch to pull in require property like the following:

"require": {
    "momentohq/client-sdk-php": "0.2.0"
  },

And 0.2.0 is created by pushing to our release branch, so I believe this is pulling from our release branch.
@pgautier404 Please correct me if I'm mistaken.

Copy link
Collaborator

Choose a reason for hiding this comment

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

@poppoerika I think the initial tag for laravel-cache is going to be 0.1.0 instead of 0.0.1.


Check out full working code in [the example app](https://github.com/momentohq/laravel-example)!

### Error Handling
Copy link
Contributor

Choose a reason for hiding this comment

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

You can remove these sections. They are not required for non-sdk projects.


### Unsupported Cache Operations

The following cache operations are not supported today:
Copy link
Contributor

Choose a reason for hiding this comment

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

can you add a bit more verbiage here and say something like: "if you need these operations, please reach out to us and we can prioritize the work to complete them. you can file a github issue, e-mail us at support@momentohq.com, or join our discord (link to discord)

Copy link
Contributor

Choose a reason for hiding this comment

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

also, can you file a github issue for us to come back and implement these? You can add the "PHP ADS 1.0" milestone to it.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Roger to both.

$keys = $this->store->setFetch($cacheName, $tag);
foreach ($keys as $k) {
if ($k == $key) {
$value = $this->store->get($key);
Copy link
Contributor

Choose a reason for hiding this comment

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

this looks to me like it would just overwrite the $value every time? And so we would end up just returning the last key that matched? but maybe there is some PHP nuance here that I am missing.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Maybe I'm misunderstanding how tagged cache get should work here...
When Cache::tags(['weather', 'seattle'])->get($cityWeatherIdInfo); is called, only the value for the key tagged with both weather and seattle needs to be returned?
In other word, if there is a key only tagged with weather, we should return null as its value?
Or as long as one of the tags are tagged to a key, we can return the value for that key?

But even with my current understanding, I need to update this for loop so that null will be assigned when $k != $key.

Copy link
Contributor

Choose a reason for hiding this comment

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

oh wow, yeah I think your understanding was closer than mine:

Cache tags allow you to tag related items in the cache and then flush all cached values that have been assigned a given tag. You may access a tagged cache by passing in an ordered array of tag names. Items stored via tags may not be accessed without also providing the tags that were used to store the value. For example, let's access a tagged cache and put a value into the cache:

So it should indeed only be returning one item, you are correct. But in that case you can break out of the loop at the point where you find a match.

We might need to think a bit more about the implementation for this. It will be easier to do when we have a way to write tests. So I think I will just give a thumbs up on this for now and we may need to re-work it once you are able to write tests.

@poppoerika
Copy link
Collaborator Author

@cprice404
I addressed all the comments above, and would like to resolve before merging this.
Yes, I'm going to add tests in a follow-up PR. This is the ticket to track: #2

Comment on lines +26 to +28
app('cache')->extend('momento', function ($app, $config) {
$store = new MomentoStore($config['cache_name'], $config['default_ttl']);
return app('cache')->repository($store);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Something about this doesn't look right to me (and my IDE). I don't think app is a function in scope here, and I'm afraid this code may not be getting called during the bootstrap process. I can't get the end-to-end Laravel example app to install for me, so I can't really troubleshoot much deeper, but please double check that this function is working correctly.

cprice404
cprice404 previously approved these changes Nov 7, 2022
Copy link
Contributor

@cprice404 cprice404 left a comment

Choose a reason for hiding this comment

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

i'm good with this going in and we can address outstanding items in follow-up, assuming @pgautier404 is also good with it

@poppoerika poppoerika merged commit 8aeea2c into main Nov 7, 2022
@poppoerika poppoerika deleted the feat/add-files-for-cache branch November 7, 2022 22:35
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