Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

In Memory Cache Laravel Package

beste/in-memory-cache

Lightweight PSR-6 in-memory cache for PHP. Ideal as a default cache implementation and for fast, dependency-free tests. Supports expirations and can use a PSR-20 clock (e.g. frozen clock) for deterministic time-based behavior.

View on GitHub
Deep Wiki
Context7

Product Decisions This Supports

  • Testing Strategy: Eliminates flaky tests caused by external cache dependencies (Redis/Memcached) by providing a deterministic, isolated in-memory cache for unit/integration tests. Aligns with Laravel’s testing best practices by enabling consistent cache behavior across environments.
  • Build vs. Buy: Reduces technical debt by replacing custom in-memory cache implementations (e.g., array()-based caches) with a PSR-6-compliant, actively maintained solution. Saves ~2–4 hours of dev time per project.
  • Performance Optimization: Enables micro-optimizations for non-critical caching layers (e.g., local dev tools, transient metrics) without bloating the stack with Redis/Memcached.
  • Fallback Mechanism: Provides a graceful degradation path for production when primary cache backends fail (e.g., Redis downtime). Can be configured as a secondary cache driver in Laravel’s config/cache.php.
  • Roadmap Alignment:
    • Supports Laravel’s PSR-6 adoption (Laravel 8+) and future-proofs caching logic.
    • Enables time-based testing via PSR-20 clocks (e.g., frozen time for TTL assertions).
    • Reduces friction for multi-environment caching strategies (e.g., CACHE_DRIVER=in_memory in .env.testing).
  • Developer Experience: Simplifies onboarding for new hires by standardizing cache behavior across dev/test/prod (with clear boundaries).

When to Consider This Package

Adopt If:

  • Your team prioritizes test reliability over raw performance in caching logic (e.g., e-commerce cart calculations, API rate limiting).
  • You need a zero-config fallback for production when Redis/Memcached is unavailable (e.g., during deployments or outages).
  • Your caching use cases are short-lived and non-persistent (e.g., local dev sessions, CI/CD pipeline caches, or transient analytics).
  • You’re migrating from custom in-memory caches (e.g., array() or Symfony\Component\Cache\Simple\ArrayCache) to a standardized PSR-6 solution.
  • Your CI/CD pipeline suffers from flaky tests due to external cache dependencies. This package eliminates that dependency entirely.
  • You’re using Laravel 8+ and want to leverage PSR-6 without adding Redis/Memcached to your stack for non-critical paths.

Avoid If:

  • Your application requires persistent caching across process restarts (e.g., user sessions, long-lived API responses).
  • You’re in a multi-server or distributed environment where shared state is mandatory (e.g., microservices, load-balanced setups).
  • Your caching needs high throughput or advanced features (e.g., cache sharding, LRU eviction, or memory limits).
  • You’re already using a production-grade cache (Redis, APCu, Memcached) and don’t need a fallback.
  • Your team lacks discipline around TTL management, risking memory leaks in long-running processes (e.g., Laravel queues, CLI scripts).
  • You’re caching complex objects (e.g., closures, resources) that serialize poorly with PHP’s native methods.

How to Pitch It (Stakeholders)

For Executives (C-Level/Finance)

*"This package lets us eliminate unreliable external dependencies in our caching layer, reducing test flakiness and deployment risks. By adopting it:

  • Saves $X/year in infrastructure costs (no Redis/Memcached for non-critical paths).
  • Reduces on-call incidents by providing a fallback cache during outages.
  • Accelerates feature delivery by standardizing caching logic across dev/test/prod.
  • Lowers technical debt with a maintained, PSR-6-compliant solution instead of custom hacks. Think of it as ‘insurance’ for your caching layer—cheap, reliable, and always available."

For Engineering Leaders (CTO/Tech Leads)

*"The beste/in-memory-cache package gives us:

  1. Test Consistency: No more flaky tests due to Redis timeouts or network issues. Tests run faster and deterministically.
  2. Fallback Resilience: A lightweight, dependency-free cache for production failovers (e.g., during deployments).
  3. Laravel Alignment: Works seamlessly with Laravel’s PSR-6 cache abstraction, requiring zero refactoring.
  4. Dev Experience: Simplifies local development by eliminating Redis setup for non-critical caching. Use it for: Testing, local dev, and fallback logic. Avoid it for production persistence or distributed setups. Risk: Minimal—MIT license, active maintenance, and zero external dependencies."*

For Developers (Backend/Full-Stack)

*"This package is your new best friend for caching in Laravel. Here’s why:

  • Install in 60 seconds: composer require beste/in-memory-cache and you’re done.
  • Test like a boss: Replace Cache::shouldReceive() with real in-memory assertions. No more mocking PSR-6 interfaces.
  • Local dev superpower: Set CACHE_DRIVER=in_memory in .env and never touch Redis again for non-critical stuff.
  • Fallback hero: When Redis is down, your app won’t crash—it’ll degrade gracefully. How to use it:
// In tests:
$cache = new Beste\Cache\InMemoryCache();
$cache->save($cache->getItem('key')->set('value'));
$this->assertTrue($cache->getItem('key')->isHit());

// In Laravel config/cache.php:
'in_memory' => [
    'driver' => 'cache',
    'store' => Beste\Cache\InMemoryCache::class,
],

Pro Tip: Pair it with beste/clock for frozen-time testing in TTL scenarios."*

For QA/DevOps

*"This package fixes our biggest test pain point: unreliable cache dependencies. Here’s how:

  • No more Redis flakiness: Tests run in isolation with predictable cache behavior.
  • CI/CD friendly: Zero external services needed—just pure PHP.
  • Production safety net: Acts as a fallback when Redis/Memcached fails, preventing outages.
  • Easy to monitor: Since it’s in-memory, you can Cache::clear() on demand (e.g., in health checks). Recommendation: Use it for all test environments and as a secondary cache driver in staging/prod with strict TTLs."*

For Product Managers

*"This is a low-risk, high-reward investment for our tech stack:

  • Faster releases: Developers spend less time debugging cache-related test failures.
  • Lower costs: Reduces reliance on managed cache services for non-critical paths.
  • Better reliability: Fallback cache prevents outages during cache service disruptions.
  • Future-proof: PSR-6 compliance ensures compatibility with Laravel’s evolving ecosystem. Ask your team: Where can we use this to remove friction from development or improve resilience?"*
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
hamzi/corewatch
minionfactory/raw-hydrator
hexters/coinpayment
rjcodes/rjcms
act-training/laravel-permissions-manager
alimarchal/laravel-chart-of-accounts
babenkoivan/elastic-scout-driver
mkwebdesign/filament-watchdog-v5
renatomarinho/laravel-page-speed
zedmagdy/filament-business-hours
renatovdemoura/blade-elements-ui
devgeek/beacon-admin
benjamin-rqt/data-watcher-bundle
atriumphp/atrium
sandermuller/package-boost-laravel
sandermuller/boost-skills
redaxo/core
yusufgenc/filament-api-forge
l3aro/rating-star-for-filament
leek/filament-subtenant-scope