以下是Ubuntu LAMP环境缓存优化技巧:
preload
预加载常用库,减少进程启动开销。swappiness=10
,降低对磁盘交换的依赖。mod_cache
和mod_cache_disk
,配置缓存路径及过期时间(如静态资源缓存1周)。CacheEnable disk /
,CacheRoot "/var/cache/apache2"
。mod_deflate
压缩HTML/CSS/JS文件,减少传输体积。Expires
或Cache-Control
头设置长期缓存(如图片缓存1个月)。my.cnf
中设置query_cache_size
(如64M),缓存高频查询结果。MEMORY
存储引擎,提升读写速度。opcache.enable=1
,opcache.memory_consumption=128
)。apcu_store()
和apcu_fetch()
操作。cron
定时清除过期缓存文件。参考来源:[1,2,3,6,7,8,9,12,13,14]