-
Notifications
You must be signed in to change notification settings - Fork 1
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
Conversation
@cprice404 @pgautier404 |
README.md
Outdated
{ | ||
"require": { | ||
"momentohq/laravel-momento-cache": "0.0.1" | ||
} | ||
} |
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.
{ | |
"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" |
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.
The repository here needs to match the require
below it:
"url": "https://github.com/momentohq/client-sdk-php" | |
"url": "https://github.com/momentohq/laravel-cache" |
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.
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"/> |
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.
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
], | ||
// ... | ||
], | ||
``` |
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 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.
src/Cache/MomentoStore.php
Outdated
public function flush() | ||
{ | ||
throw new UnknownError("flush operations is currently not supported."); | ||
} |
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.
We probably need to record this list of unsupported operations in the README as well.
src/Cache/MomentoStore.php
Outdated
|
||
public function increment($key, $value = 1) | ||
{ | ||
return false; |
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.
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.
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.
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.
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.
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.
src/Cache/MomentoStore.php
Outdated
|
||
public function forget($key) | ||
{ | ||
throw new UnknownError("forget operations is currently not supported."); |
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 believe that we can implement this one today?
src/Cache/MomentoServiceProvider.php
Outdated
|
||
use Illuminate\Support\ServiceProvider; | ||
|
||
class MomentoServiceProvider extends ServiceProvider |
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.
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?
src/Cache/MomentoTaggedCache.php
Outdated
{ | ||
$tags = $this->tags->getNames(); | ||
$cacheName = $this->store->getCacheName(); | ||
$value = "erika"; |
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.
?
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.
Yup. I noticed that too. I will update it 🙇♀️
src/Cache/MomentoTaggedCache.php
Outdated
} | ||
return $value; | ||
} | ||
} |
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.
is there any way to add a few simple integration tests to this repo?
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 wanted to add it in a follow-up PR if it's okay.
I added the branch protection rules for |
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 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 |
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.
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 |
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 think we want to do readme generation on the release step, I think you can remove this.
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 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)
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.
okay
"repositories": [ | ||
{ | ||
"type": "vcs", | ||
"url": "https://github.com/momentohq/laravel-cache" |
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.
will these be the correct directions for pulling from our release branch?
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.
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.
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.
@poppoerika I think the initial tag for laravel-cache
is going to be 0.1.0
instead of 0.0.1
.
README.template.md
Outdated
|
||
Check out full working code in [the example app](https://github.com/momentohq/laravel-example)! | ||
|
||
### Error Handling |
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.
You can remove these sections. They are not required for non-sdk projects.
README.template.md
Outdated
|
||
### Unsupported Cache Operations | ||
|
||
The following cache operations are not supported today: |
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.
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)
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.
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.
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.
Roger to both.
$keys = $this->store->setFetch($cacheName, $tag); | ||
foreach ($keys as $k) { | ||
if ($k == $key) { | ||
$value = $this->store->get($key); |
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 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.
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.
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
.
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.
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.
@cprice404 |
app('cache')->extend('momento', function ($app, $config) { | ||
$store = new MomentoStore($config['cache_name'], $config['default_ttl']); | ||
return app('cache')->repository($store); |
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.
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.
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'm good with this going in and we can address outstanding items in follow-up, assuming @pgautier404 is also good with it
Moved all the files from my personal repo.
Relevant ticket: https://github.com/momentohq/dev-eco-issue-tracker/issues/126