#12. Memcache
Uninstallation/Installation,
sudo apt-get remove memcached
sudo apt-get remove --auto-remove memcached
sudo apt update && sudo apt upgrade
sudo apt install memcached
# For the use of mem-cache
gem 'dalli'
root@test_app:~# memcached -h | head -1
memcached 1.5.22
rails dev:cache
root@test_app:~# ls tmp/
cache data development_secret.txt miniprofiler pids res restart.txt sockets
root@test_app:~# rails dev:cache
Development mode is now being cached.
root@test_app:~# ls tmp/
cache caching-dev.txt data development_secret.txt miniprofiler pids res restart.txt sockets
root@test_app:~# rails dev:cache
Development mode is no longer being cached.
root@test_app:~# ls tmp/
cache data development_secret.txt miniprofiler pids res restart.txt sockets
touch tmp/restart.txt
root@test_app:~# ls tmp/
cache caching-dev.txt data development_secret.txt miniprofiler pids res restart.txt sockets
root@test_app:~# touch tmp/restart.txt
root@test_app:~# ls tmp/
cache caching-dev.txt data development_secret.txt miniprofiler pids res restart.txt sockets
Inside container,
/etc/init.d/memcached status
or
service memcached status
/etc/init.d/memcached restart
or
service memcached restart
apt-get update && apt-get install telnet
root@test_app:~# telnet 127.0.0.1 11211
Trying 127.0.0.1...
telnet: Unable to connect to remote host: Connection refused
Ctrl + ] - to close telnet connection
log file,
cat /var/log/memcached.log
config file,
sudo vim /etc/memcached.conf
Examples,
Rails.cache.write("foo", "bar")
puts Rails.cache.read("foo")
def fetch_current_time
rails. Cache. Fetch('current_time', expires_in: 10. Seconds) do
time. Now
end
end
while true
puts fetch_current_time
sleep 9
end
def fetch_api_settings
rails. Cache. Fetch('api_settings', expires_in: 1. Minutes) do
ApiSetting. All
end
end
while true
puts fetch_api_settings
end
Default IP and port,
'127.0.0.1:11211'
Useful commands
sudo systemctl stop memcached
sudo systemctl start memcached
sudo systemctl restart memcached
sudo systemctl status memcached
Socket settings
# -p 11211
List files
References:
1. https://www.rubydoc.info/github/mperham/dalli/Dalli%2FClient:initialize
2. https://guides.wp-bullet.com/configure-memcached-to-use-unix-socket-speed-boost/
Comments
Post a Comment
Let me know for any query..