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

[11.x] Add setters to cache stores #50912

Merged
merged 3 commits into from
Apr 4, 2024

Conversation

stancl
Copy link
Contributor

@stancl stancl commented Apr 3, 2024

This makes it so that each cache store that respects the cache.prefix config also has a setter for the prefix. The prefix can be useful to change at runtime to separate cache data further, e.g. by tenants instead of just by application.

@stancl stancl changed the title [11.x] Add setPrefix() to ApcStore and DatabaseStore [11.x] Add setters to cache stores Apr 4, 2024
@stancl
Copy link
Contributor Author

stancl commented Apr 4, 2024

I've added one more setter: setDirectory() in FileStore. FileStore doesn't respect the cache.prefix (since it has no reason to, being application-specific and not a shared resource like Redis), therefore cache can be separated within an application by changing the cache directory instead.

I don't need this change as much as the others so if you don't like it I can revert, but it lets me change the cache directory in our tenancy package directly instead of having to hot-swap the underlying Store for a Cache Repository:

// update the path for the cache store in the config and then:
$newStore = $this->app['cache']->resolve($name);
$repository = $this->app['cache']->store($name);
$repository->setStore($newStore);

Now it's just

$this->app['cache']->store($name)->getStore()->setDirectory($path);

There's already an existing setter for the lock directory, this implements it in the same way (also returns $this).

@taylorotwell taylorotwell merged commit 3002511 into laravel:11.x Apr 4, 2024
28 checks passed
@stancl
Copy link
Contributor Author

stancl commented Apr 4, 2024

Thanks!

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.

2 participants