asanikovich/
laravel-roadrunner-cache
g4t.io

RoadRunner Key-Value Cache for Laravel

20 views 38 stars by Paul Redmond

RoadRunner KV cache for laravel

README from asanikovich/laravel-roadrunner-cache Open on GitHub →

Laravel RoadRunner Cache

Latest Version on Packagist GitHub Tests Status GitHub Tests Coverage Status GitHub Code Style Status GitHub Lint Status Total Downloads Licence

This Laravel package allows you to work with RoadRunner KV Cache in Laravel (as a cache driver).

For laravel/octane users

Please note, that swoole in-memory or table cache works only inside HTTP workers.

If you want a cache that works from all parts of PHP (HTTP or CLI) - our package and RoadRunner KV will help you.

Getting Started

Installing the Package

You can install the package via composer:

composer require asanikovich/laravel-roadrunner-cache

Configuration

Configuration RoadRunner

Make sure you have in your RoadRunner config file (.rr.yaml) next sections:

  • RPC section
  • KV section

Full example of RoadRunner configuration file:

version: '3'
rpc:
  listen: 'tcp://127.0.0.1:6001'
server:
  command: php /var/www/html/vendor/bin/roadrunner-worker
http:
  address: '127.0.0.1:8080'
  pool:
    num_workers: 1
kv:
    memory:
        driver: memory
        config:
            interval: 1
    boltdb:
        driver: boltdb
        config:
            interval: 1

Publish config

Publish the config file and setup RPC connection:

php artisan vendor:publish --tag="laravel-roadrunner-cache-config"

Serializers

Package supports next serializers (should be configured in store config):

  • null - default php serializer
  • igbinary - igbinary serializer, ext-igbinary is required to be installed

Encryption

Package supports encryption with sodium, requirements:

  • ext-sodium required to be installed
  • encryption_key filled in store config (generated by sodium_crypto_box_keypair())

Setup cache config file

Add to cache configuration file (/config/cache.php) new store with driver roadrunner:

Config file example

<?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-boltdb' => [ // Custom store name with "boltdb" connection (another store is optional)
            'driver' => 'roadrunner',
            'connection' => 'boltdb', // 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
            'prefix' => 'custom', // Custom prefix - non-empty-string
        ],
        'rr-memory-igbinary' => [ // Custom store name with "memory" connection and "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' => 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
        ],
    ],
]

Usage

To use in your code:

<?php
    use Illuminate\Support\Facades\Cache;

    Cache::driver()->get('key'); // Default main store - rr-memory
    Cache::driver('rr-boltdb')->get('key'); // rr-boltdb store

All done! 🚀

Development

Here are some useful commands for development

Before running tests run docker-compose:

docker-compose up -d

Run tests:

composer run test

Run tests with coverage:

composer run test-coverage

Perform type checking:

composer run phpstan

Format your code:

composer run format

Updates and Changes

For details on updates and changes, please refer to our CHANGELOG.

License

Laravel RoadRunner Cache is released under The MIT License (MIT). For more information, please see our License File.

More from the ecosystem

durable-workflow/
workflow
g4t.io
9 1,292

Durable Workflow: Long-Running Workflows for Laravel

Embedded durable workflow runtime and orchestration engine for Laravel applications.

durable-workflow/workflow via Laravel News
packstub/
session-replay
g4t.io
14 52

Session Replay for Laravel: Self-Hosted Browser Recordings

Session replay for Laravel: record what a person did in the browser with rrweb, keep the recording on your own disk and database, and watch it behind a gate you define — masked inputs by default, errors, failed Livewire requests and web vitals marked on the timeline, a link to the replay in every log line. packstub/filament-session-replay adds the sessions to a Filament panel.

packstub/session-replay via Laravel News
cyberwizard-dev/
schedule-catchup
g4t.io
17

Replay Missed Laravel Scheduled Tasks With Schedule Catchup

Schedule Catchup replays missed Laravel scheduled tasks after downtime, with opt-in recovery, bounded retries, and access to the original scheduled date.

cyberwizard-dev/schedule-catchup via Laravel News