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

Cache Laravel Package

gregwar/cache

gregwar/cache is a lightweight PHP caching library with a simple API for caching values and function results. Supports multiple backends (filesystem, APC/APCu, memcache), TTL expiration, cache namespaces/prefixes, and easy integration into existing apps.

View on GitHub
Deep Wiki
Context7

A lightweight filesystem caching system

Frequently asked questions about Cache
How do I integrate gregwar/cache with Laravel’s Cache facade?
gregwar/cache implements a PSR-6-like interface, so you can bind it to Laravel’s Cache facade by registering a service provider. Use `Cache::extend()` to create a custom driver that wraps the gregwar/cache instance. This allows you to use `Cache::get()` and `Cache::put()` with the library’s backend.
What backends does gregwar/cache support out of the box?
The package supports filesystem caching natively and includes adapters for APC/APCu. For other backends like Redis or Memcached, you’ll need to create custom adapters or use Laravel’s built-in drivers alongside it. The filesystem backend is the most lightweight and requires no external dependencies.
Can I use gregwar/cache for Laravel’s queue job caching or job result storage?
Yes, gregwar/cache is suitable for caching queue job results or expensive computations, especially if you need lightweight, transient storage. Use the `getOrSet()` helper to memoize job execution results. However, avoid it for distributed systems where consistency is critical—consider Redis or database caching instead.
How does gregwar/cache handle cache invalidation compared to Laravel’s native drivers?
gregwar/cache supports TTL (time-to-live) expiration for automatic invalidation, but lacks Laravel’s tag-based invalidation system. You’ll need to manually delete keys or implement a custom tagging system. For large-scale apps, consider using Laravel’s native cache drivers for advanced invalidation features.
Is gregwar/cache thread-safe for concurrent writes in Laravel’s queue workers?
gregwar/cache does not include built-in locking mechanisms, so concurrent writes to the same cache key can lead to race conditions or file corruption. Use PHP’s `flock()` or Laravel’s cache locking (`Cache::lock()`) to mitigate this risk in multi-process environments like queue workers.
How do I customize serialization for complex objects in gregwar/cache?
gregwar/cache supports custom serializers via the `setSerializer()` method. For complex objects, you can implement a custom serializer that converts data to JSON or a custom format. Avoid PHP’s native `serialize()` if security is a concern, as it can lead to object injection vulnerabilities.
What’s the performance difference between gregwar/cache and Laravel’s file cache driver?
gregwar/cache and Laravel’s file driver are functionally similar, but gregwar/cache offers more granular control over serialization and cache directories. Performance-wise, both are I/O-bound, so expect slower reads/writes than in-memory caches like APCu or Redis. Benchmark both in your environment to compare.
Can I use gregwar/cache as a fallback when Redis or Memcached fails in Laravel?
Yes, gregwar/cache is a good fallback for transient data when primary caches fail. Configure Laravel’s cache driver to automatically fall back to gregwar/cache by extending the `Cache` facade with a conditional driver. This ensures graceful degradation without application downtime.
How do I test gregwar/cache in Laravel’s unit tests?
Mock the filesystem operations or use in-memory adapters (like APCu) for testing. For filesystem testing, create a temporary directory and configure gregwar/cache to use it. Laravel’s `Storage::fake()` can also be adapted to simulate cache operations if you’re testing custom drivers.
Are there any security risks I should be aware of when using gregwar/cache in production?
The main risks are path traversal if cache keys aren’t sanitized and deserialization vulnerabilities if using custom serializers. Always store the cache directory outside the web root, validate keys, and prefer JSON serialization over PHP’s `unserialize()` for security. Regularly audit cache contents for suspicious data.
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.
codeflextech/permission-manager
karnoweb/livewire-datepicker
sayedenam/sayed-dashboard
milito/query-filter
apiboxsym/user-bundle
apiboxsym/health-check-bundle
jayeshmepani/jpl-moshier-ephemeris-php
elnasnato/laraliveui
labrodev/rest-sdk
sampaui/sampaui
babelqueue/php-sdk
facebook/capi-param-builder-php
babelqueue/symfony
hamzi/corewatch
minionfactory/raw-hydrator
hexters/coinpayment
rjcodes/rjcms
act-training/laravel-permissions-manager
alimarchal/laravel-chart-of-accounts
babenkoivan/elastic-scout-driver