Download

Free Resource v1.1.0

Cache

A high-performance, pluggable PHP caching library with Redis, file, session, and memory drivers. TweekersNut Cache is a professional, production-ready caching solution designed to speed up backend processing, data fetching, and manipulation. It provides a unified interface for multiple cache drivers, making it easy to switch between different caching strategies without changing your code.

Cache

Access

Free Download

Instant access ยท No signup required

TweekersNut Cache

๐Ÿ“ฆ Installation

Install via Composer:

composer require tweekersnut/cache

Requirements

  • PHP >= 8.0
  • (Optional) Redis extension for Redis driver
  • (Optional) Predis library as alternative to Redis extension

๐ŸŽฏ Quick Start

Basic Usage

<?php

require 'vendor/autoload.php';

use TweekersNut\Cache\Cache;

// Create a cache instance
$cache = Cache::make([
    'driver' => 'file',
    'path' => '/path/to/cache',
    'prefix' => 'myapp:',
    'ttl' => 3600
]);

// Store data
$cache->set('user:1', ['name' => 'John Doe', 'email' => 'john@example.com'], 600);

// Retrieve data
$user = $cache->get('user:1');

// Check if key exists
if ($cache->has('user:1')) {
    echo "User found in cache!";
}

// Delete a key
$cache->delete('user:1');

// Clear all cache
$cache->clear();

Static Facade Usage

use TweekersNut\Cache\Cache;

// Configure once
Cache::setInstance(Cache::make(['driver' => 'redis', 'host' => '127.0.0.1']));

// Use anywhere
Cache::set('key', 'value', 300);
$value = Cache::get('key');

๐Ÿ”ง Configuration

Redis Driver

$cache = Cache::make([
    'driver' => 'redis',
    'host' => '127.0.0.1',
    'port' => 6379,
    'password' => 'secret',      // Optional
    'database' => 0,             // Optional (default: 0)
    'timeout' => 2.5,            // Optional (default: 2.5)
    'prefix' => 'myapp:',        // Optional
    'ttl' => 3600                // Optional default TTL
]);

Requirements: PHP Redis extension (ext-redis) or Predis library

Best For: High-traffic applications, distributed systems, shared cache across servers

File Cache Driver

$cache = Cache::make([
    'driver' => 'file',
    'path' => '/var/www/cache',  // Cache directory
    'prefix' => 'myapp:',        // Optional
    'ttl' => 3600                // Optional default TTL
]);

Best For: Single-server applications, development, when Redis is unavailable

Session Cache Driver

$cache = Cache::make([
    'driver' => 'session',
    'prefix' => 'cache:',        // Optional
    'ttl' => 1800                // Optional default TTL
]);

Best For: Per-user caching, temporary user-specific data

Array (Memory) Cache Driver

$cache = Cache::make([
    'driver' => 'array',
    'prefix' => 'temp:',         // Optional
    'ttl' => 300                 // Optional default TTL
]);

Best For: Testing, single-request caching, temporary runtime data

๐Ÿ”„ Driver Comparison

Feature Redis File Session Array
Persistence โœ… Yes โœ… Yes โš ๏ธ Session only โŒ No
Multi-Server โœ… Yes โŒ No โŒ No โŒ No
Performance โšก Excellent โš ๏ธ Good โš ๏ธ Good โšก Excellent
Setup Required โœ… Redis server โŒ None โŒ None โŒ None
Memory Usage โš ๏ธ External โš ๏ธ Disk โš ๏ธ Session โš ๏ธ PHP memory
Best For Production Development User data Testing

 

Demo Video

What you'll get

Multiple Cache Drivers: Redis, File, Session, and Array (in-memory)

Unified Interface: Consistent API across all drivers

PSR-4 Autoloading: Modern PHP standards

Type-Safe: Full PHP 8.0+ type hints

Zero Dependencies: No framework required (works standalone)

High Performance: Optimized for production environments

TTL Support: Time-to-live for automatic expiration

Prefix/Namespace Support: Avoid key collisions

Remember Pattern: Cache-or-execute in one call

Increment/Decrement: Atomic counter operations

Exception-Safe: Never breaks application flow