Use memcached for laravel on multiple sites
On a server I have about 25 websites running the same laravel based backed. I want to change the session&cache driver from file to memcached. But this causes a cached data mixup. e.g. I see the menu from site 1 on site 2.
How can I use memcached on multiple sites?
laravel memcached
add a comment |
On a server I have about 25 websites running the same laravel based backed. I want to change the session&cache driver from file to memcached. But this causes a cached data mixup. e.g. I see the menu from site 1 on site 2.
How can I use memcached on multiple sites?
laravel memcached
add a comment |
On a server I have about 25 websites running the same laravel based backed. I want to change the session&cache driver from file to memcached. But this causes a cached data mixup. e.g. I see the menu from site 1 on site 2.
How can I use memcached on multiple sites?
laravel memcached
On a server I have about 25 websites running the same laravel based backed. I want to change the session&cache driver from file to memcached. But this causes a cached data mixup. e.g. I see the menu from site 1 on site 2.
How can I use memcached on multiple sites?
laravel memcached
laravel memcached
asked Dec 30 '18 at 9:03
PatrickPatrick
63
63
add a comment |
add a comment |
3 Answers
3
active
oldest
votes
I think the only possible way of doing this would be to have unique cache keys for each website.
It could be based on a unique website identifier (id or url).
I think the logic to retrieve the cache keys could also be encapsulated a bit. In my current setup, I have something a little similar whereby the cache keys are different depending on the locale.
protected function getCacheKey($key, $locale = null)
{
$prefix = '__app_cache_';
$suffix = $locale ? "_$locale" : '';
return $prefix . $key . $suffix;
}
For example, your logic could be something like this:
protected function getCacheKey($key, Website $website)
{
$prefix = '__app_cache_';
$suffix = "_{$website->id}" : '';
return $prefix . $key . $suffix;
}
and then to get the menu
cache key, you would do something like this:
$cache->getCacheKey($menu, $website);
This is, obviously, just an example and needs to be adapted to your specific needs.
add a comment |
Based on the idea of a prefix I found a nicer solution for Laravel. But somehow I cant find this on the internet.
In the cache.php file I added an extra key options with the memcached prefix option that is available in the memcached documentation:
'memcached' => [
'driver' => 'memcached',
'servers' => [
[
'host' => '127.0.0.1', 'port' => 11211, 'weight' => 100
],
],
'options' => [
Memcached::OPT_PREFIX_KEY => "websitename",
],
],
Now all the sites can run without issues
add a comment |
Brother, If you haven't used Memcached with Laravel then I would prefer to go with Redis, It has more good speed in easy to work with Laravel.
@Patrick also you can use this with multiple key based the key pattern, Like Domain name and key and unique id, somedomain_key_uniqueID.
– Muhammad Adil
Dec 31 '18 at 8:40
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53976373%2fuse-memcached-for-laravel-on-multiple-sites%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
I think the only possible way of doing this would be to have unique cache keys for each website.
It could be based on a unique website identifier (id or url).
I think the logic to retrieve the cache keys could also be encapsulated a bit. In my current setup, I have something a little similar whereby the cache keys are different depending on the locale.
protected function getCacheKey($key, $locale = null)
{
$prefix = '__app_cache_';
$suffix = $locale ? "_$locale" : '';
return $prefix . $key . $suffix;
}
For example, your logic could be something like this:
protected function getCacheKey($key, Website $website)
{
$prefix = '__app_cache_';
$suffix = "_{$website->id}" : '';
return $prefix . $key . $suffix;
}
and then to get the menu
cache key, you would do something like this:
$cache->getCacheKey($menu, $website);
This is, obviously, just an example and needs to be adapted to your specific needs.
add a comment |
I think the only possible way of doing this would be to have unique cache keys for each website.
It could be based on a unique website identifier (id or url).
I think the logic to retrieve the cache keys could also be encapsulated a bit. In my current setup, I have something a little similar whereby the cache keys are different depending on the locale.
protected function getCacheKey($key, $locale = null)
{
$prefix = '__app_cache_';
$suffix = $locale ? "_$locale" : '';
return $prefix . $key . $suffix;
}
For example, your logic could be something like this:
protected function getCacheKey($key, Website $website)
{
$prefix = '__app_cache_';
$suffix = "_{$website->id}" : '';
return $prefix . $key . $suffix;
}
and then to get the menu
cache key, you would do something like this:
$cache->getCacheKey($menu, $website);
This is, obviously, just an example and needs to be adapted to your specific needs.
add a comment |
I think the only possible way of doing this would be to have unique cache keys for each website.
It could be based on a unique website identifier (id or url).
I think the logic to retrieve the cache keys could also be encapsulated a bit. In my current setup, I have something a little similar whereby the cache keys are different depending on the locale.
protected function getCacheKey($key, $locale = null)
{
$prefix = '__app_cache_';
$suffix = $locale ? "_$locale" : '';
return $prefix . $key . $suffix;
}
For example, your logic could be something like this:
protected function getCacheKey($key, Website $website)
{
$prefix = '__app_cache_';
$suffix = "_{$website->id}" : '';
return $prefix . $key . $suffix;
}
and then to get the menu
cache key, you would do something like this:
$cache->getCacheKey($menu, $website);
This is, obviously, just an example and needs to be adapted to your specific needs.
I think the only possible way of doing this would be to have unique cache keys for each website.
It could be based on a unique website identifier (id or url).
I think the logic to retrieve the cache keys could also be encapsulated a bit. In my current setup, I have something a little similar whereby the cache keys are different depending on the locale.
protected function getCacheKey($key, $locale = null)
{
$prefix = '__app_cache_';
$suffix = $locale ? "_$locale" : '';
return $prefix . $key . $suffix;
}
For example, your logic could be something like this:
protected function getCacheKey($key, Website $website)
{
$prefix = '__app_cache_';
$suffix = "_{$website->id}" : '';
return $prefix . $key . $suffix;
}
and then to get the menu
cache key, you would do something like this:
$cache->getCacheKey($menu, $website);
This is, obviously, just an example and needs to be adapted to your specific needs.
edited Dec 30 '18 at 10:02
answered Dec 30 '18 at 9:21
MozammilMozammil
5,096419
5,096419
add a comment |
add a comment |
Based on the idea of a prefix I found a nicer solution for Laravel. But somehow I cant find this on the internet.
In the cache.php file I added an extra key options with the memcached prefix option that is available in the memcached documentation:
'memcached' => [
'driver' => 'memcached',
'servers' => [
[
'host' => '127.0.0.1', 'port' => 11211, 'weight' => 100
],
],
'options' => [
Memcached::OPT_PREFIX_KEY => "websitename",
],
],
Now all the sites can run without issues
add a comment |
Based on the idea of a prefix I found a nicer solution for Laravel. But somehow I cant find this on the internet.
In the cache.php file I added an extra key options with the memcached prefix option that is available in the memcached documentation:
'memcached' => [
'driver' => 'memcached',
'servers' => [
[
'host' => '127.0.0.1', 'port' => 11211, 'weight' => 100
],
],
'options' => [
Memcached::OPT_PREFIX_KEY => "websitename",
],
],
Now all the sites can run without issues
add a comment |
Based on the idea of a prefix I found a nicer solution for Laravel. But somehow I cant find this on the internet.
In the cache.php file I added an extra key options with the memcached prefix option that is available in the memcached documentation:
'memcached' => [
'driver' => 'memcached',
'servers' => [
[
'host' => '127.0.0.1', 'port' => 11211, 'weight' => 100
],
],
'options' => [
Memcached::OPT_PREFIX_KEY => "websitename",
],
],
Now all the sites can run without issues
Based on the idea of a prefix I found a nicer solution for Laravel. But somehow I cant find this on the internet.
In the cache.php file I added an extra key options with the memcached prefix option that is available in the memcached documentation:
'memcached' => [
'driver' => 'memcached',
'servers' => [
[
'host' => '127.0.0.1', 'port' => 11211, 'weight' => 100
],
],
'options' => [
Memcached::OPT_PREFIX_KEY => "websitename",
],
],
Now all the sites can run without issues
answered Dec 31 '18 at 8:37
PatrickPatrick
63
63
add a comment |
add a comment |
Brother, If you haven't used Memcached with Laravel then I would prefer to go with Redis, It has more good speed in easy to work with Laravel.
@Patrick also you can use this with multiple key based the key pattern, Like Domain name and key and unique id, somedomain_key_uniqueID.
– Muhammad Adil
Dec 31 '18 at 8:40
add a comment |
Brother, If you haven't used Memcached with Laravel then I would prefer to go with Redis, It has more good speed in easy to work with Laravel.
@Patrick also you can use this with multiple key based the key pattern, Like Domain name and key and unique id, somedomain_key_uniqueID.
– Muhammad Adil
Dec 31 '18 at 8:40
add a comment |
Brother, If you haven't used Memcached with Laravel then I would prefer to go with Redis, It has more good speed in easy to work with Laravel.
Brother, If you haven't used Memcached with Laravel then I would prefer to go with Redis, It has more good speed in easy to work with Laravel.
answered Dec 31 '18 at 8:39
Muhammad AdilMuhammad Adil
468
468
@Patrick also you can use this with multiple key based the key pattern, Like Domain name and key and unique id, somedomain_key_uniqueID.
– Muhammad Adil
Dec 31 '18 at 8:40
add a comment |
@Patrick also you can use this with multiple key based the key pattern, Like Domain name and key and unique id, somedomain_key_uniqueID.
– Muhammad Adil
Dec 31 '18 at 8:40
@Patrick also you can use this with multiple key based the key pattern, Like Domain name and key and unique id, somedomain_key_uniqueID.
– Muhammad Adil
Dec 31 '18 at 8:40
@Patrick also you can use this with multiple key based the key pattern, Like Domain name and key and unique id, somedomain_key_uniqueID.
– Muhammad Adil
Dec 31 '18 at 8:40
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53976373%2fuse-memcached-for-laravel-on-multiple-sites%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown