Weave 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

hyperf/cache

Hyperf/Cache is the coroutine-safe caching component for the Hyperf PHP framework. It provides PSR-16 simple cache, Redis, memory, and file adapters, cache annotations, and configurable TTLs for fast, convenient caching in coroutine applications.

View on GitHub
Deep Wiki
Context7

A cache component for hyperf.

Frequently asked questions about Cache
What is hyperf/cache used for?
hyperf/cache is the caching component for the Hyperf PHP framework. It provides a PSR-16 SimpleCache-compatible interface and coroutine-safe Redis, memory, and file drivers, so you can switch storage backends without changing application code. It also supports TTLs, default values, key prefixes, and cache annotations such as @Cacheable, @CachePut, and @CacheEvict.
How do I install hyperf/cache with Composer?
Install it with composer require hyperf/cache. In a Hyperf application you then choose a default cache driver and optional key prefix in your cache configuration. The component's driver manager wires the selected adapter to the PSR-16 CacheInterface.
Does hyperf/cache work in Laravel applications?
No, hyperf/cache is built for the Hyperf framework and its coroutine runtime. Laravel has its own cache component with a similar PSR-16-style API, but hyperf/cache is not a drop-in Laravel replacement. Use Laravel's cache package for Laravel apps and hyperf/cache for Hyperf apps.
How do I configure drivers, TTLs, and key prefixes in hyperf/cache?
Choose a default driver such as Redis, memory, or file, and optionally set a key prefix and default TTL in the cache configuration. Because everything implements PSR-16, you can also pass a TTL per set call and a default value per get call. Switching drivers does not require changes to application code.
Is hyperf/cache safe to use with coroutines?
Yes, hyperf/cache is designed for coroutine-based Hyperf applications. Its Redis, memory, and file drivers are implemented to be coroutine-safe, avoiding shared-state problems that can affect traditional cache clients. This makes it suitable for high-concurrency Hyperf services.
What do @Cacheable, @CachePut, and @CacheEvict do in hyperf/cache?
These are annotation-based caching helpers for Hyperf methods. @Cacheable reads from cache and stores the method result when a cache miss occurs, @CachePut writes or refreshes a cached value, and @CacheEvict removes cached entries. They reduce boilerplate compared with calling the PSR-16 API manually.
Can I register a custom cache driver in hyperf/cache?
Yes, hyperf/cache provides a driver manager for registering custom adapters. You implement the required cache behavior and register your driver so it can be selected through configuration like the built-in Redis, memory, and file drivers. This is useful when you need a backend that the package does not ship by default.
How should I test code that uses hyperf/cache?
For unit tests, use the memory driver or mock the PSR-16 CacheInterface so tests do not depend on Redis or the filesystem. Keep cache keys and TTL expectations explicit in your assertions. Integration tests can then cover the real Redis or file driver separately.
What should I consider before using hyperf/cache in production?
Pick a shared backend like Redis when cache data must be consistent across workers, and set sensible TTLs and key prefixes to avoid collisions. Monitor Redis availability and memory usage, and avoid relying on the memory driver for data that must survive process restarts. Also verify that your chosen driver matches your Hyperf runtime and deployment topology.
What are alternatives to hyperf/cache?
Inside Hyperf, hyperf/cache is the framework's native caching component and integrates with its coroutine runtime. For Laravel applications, use Laravel's cache component; for framework-agnostic code, other PSR-16 implementations or Symfony Cache may fit. Choose based on whether you need Hyperf coroutine safety and annotations.
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.
vento/laravel-airbrake
wfeller/laravel-batch
maco-studios/mage-os-installer
busarm/armie
siberfx/laravel-logger
kfteam1991/dcat-admin
dashed/dashed-laposta
dashed/dashed-ecommerce-montaportal
dashed/dashed-ecommerce-etsy
neohq/string-blade-compiler
log1x/acf-composer
cgv/localized-resource
noith/settings
kda/laravel-package
kda/filament-dynamic-navigation
bypersoft/signbox
pairus/product-data
fayne/laravel-filament-cms-core
nodisrupt/laravel-agent
sierratecnologia/media-manager