编程

Laravel RoadRunner Key-Value 缓存

947 2023-09-20 21:56:00

Laravel Roadrunner KV Cache 包允许您使用 RoadRunner 键值插件作为缓存驱动程序:

use Illuminate\Support\Facades\Cache;
 
// Default main store - rr-memory
Cache::driver()->get('key');
 
// rr-boltdb store
Cache::driver('rr-boltdb')->get('key');

Key-Value 插件允许在 RoadRunner 中存储不同 HTTP 请求或 CLI 等其他类型应用程序之间的任意数据。

通过 Roadrunner,该软件包支持内存存储,如果您需要持久存储,则支持 boltdb 驱动程序。如果您的数据可能包含敏感信息(如个人用户数据),它还支持端到端加密序列化。

与任何缓存驱动程序一样,您可以使用 RoadRunner 的 Key Value 驱动程序配置多个选项。以下是自述文件中缓存配置示例中的一些示例配置选项:

<?php
return [
    'default' => 'rr-memory', // Default store (optional)
 
    'stores' => [
        'rr-memory' => [ // Custom store name with "memory" connection
            'driver' => 'roadrunner',
            'connection' => 'memory', // section name from KV plugin settings in RoadRunner config file (.rr.yaml)
            'serializer' => null, // Available options: null|igbinary
            'encryption_key' => null, // Available options: null|string
        ],
        'rr-memory-igbinary-encrypted' => [ // Custom store name with "memory" connection and encrypted "igbinary" serializer
            'driver' => 'roadrunner',
            'connection' => 'memory', // section name from KV plugin settings in RoadRunner config file (.rr.yaml)
            'serializer' => 'igbinary', // Available options: null|igbinary
            'encryption_key' => 'key1', // Available options: null|string
        ],
         'rr-memory-encrypted' => [ // Custom store name with "memory" connection and encrypted serializer
            'driver' => 'roadrunner',
            'connection' => 'memory', // section name from KV plugin settings in RoadRunner config file (.rr.yaml)
            'serializer' => null, // Available options: null|igbinary
            'encryption_key' => 'key2', // Available options: null|string
        ],
    ],
],

了解更多信息可查看 Github 源码