# Cache [https://github.com/hyperf/cache](https://github.com/hyperf/cache) ## Config ```php [ 'driver' => Hyperf\Cache\Driver\RedisDriver::class, 'packer' => Hyperf\Cache\Packer\PhpSerializer::class, ], ]; ``` ## How to use Components provide Cacheable annotation to configure cache prefix, expiration times, listeners, and cache groups. For example, UserService provides a user method to query user information. When the Cacheable annotation is added, the Redis cache is automatically generated with the key value of `user:id` and the timeout time of 9000 seconds. When querying for the first time, it will be fetched from DB, and when querying later, it will be fetched from Cache. ```php where('id',$id)->first(); if($user){ return $user->toArray(); } return null; } } ``` ## Clear Cache Of course, if the data changes, how to delete the cache? Here we need to use the listener. Next, a new Service provides a way to help us deal with it. ```php dispatcher->dispatch(new DeleteListenerEvent('user-update', [$userId])); return true; } } ```