Home
Quick start
Documentation
Forum
GitHub
Home
Quick start
Documentation
Forum
GitHub
  • Quick Start

    • Introduction
    • Why Phico
    • Installation
  • Example app

    • Scaffolding
    • Routes
    • Requests
    • Responses
    • Events
  • Phico

    • CLI
    • Config
    • Container
    • Filesystem
    • Logger
    • Middleware
    • Request
    • Response
    • Router
    • Support
    • View
  • Libraries

    • Authentication
    • Cache
    • CDN
    • Database
    • Http client
    • Locale
    • Mailer
    • Profiler
    • Query
    • Queue
    • Validation
    • Session
    • View
  • Works

    • Introduction

Cache

Lightweight cache support.

Installation

Using composer

composer require phico/cache

Config

Cache requires a specific config format for each driver

[

    'use' => env('CACHE_USE', 'default'),

    'drivers' => [

        'file' => [
            'path' => env('CACHE_FILESYSTEM_PATH', '/storage/cache'),
        ],

        'redis' => [
            'scheme' => env('CACHE_REDIS_SCHEME', 'tcp'),
            'host' => env('CACHE_REDIS_HOST', '127.0.0.1'),
            'port' => env('CACHE_REDIS_PORT', 6379),
        ],

    ],
];

Usage

Cache provides quick and simple access to cache servers such as Redis, KeyDB and Valkey.

$use = $config['use'];
$cache = new Cache($config['drivers'][$use]);
// set an item in the cache
$cache->set('foo', 'bar');

// get an item from the cache
$value = $cache->get('foo');
// $value = 'bar'

// remove an item from cache
$cache->delete('foo');

// check existence
$exists = $cache->exists('foo'):
// $exists = false
Last Updated:
Contributors: indgy
Prev
Authentication
Next
CDN