tenantcloud/laravel-better-cache

对 Laravel 缓存的改进

v1.0.0-alpha.6 2023-11-15 11:33 UTC

README

安全模式

Laravel 缓存的实现不允许失败 - 如果你的 Redis 崩溃,你的应用程序也会崩溃。新的 fail_safe 驱动器旨在通过捕获并记录所有异常,并返回 null/false 代替缓存中未找到的值来解决这个问题。

// config/cache.php
[
	'fail_safe' => [
		'delegate' => [
			'driver' => 'redis',
			'connection' => 'cache',
			'lock_connection' => 'default',
		]
	]
]

// code
Cache::forever('key', 'value');
// redis died here
Cache::get('key'); // returns null and logs the exception