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?
3
Answers
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:
Now all the sites can run without issues
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.
For example, your logic could be something like this:
and then to get the
menu
cache key, you would do something like this:This is, obviously, just an example and needs to be adapted to your specific needs.
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.