V
V
Valera2018-06-19 13:12:03
Yii
Valera, 2018-06-19 13:12:03

Yii2 how to set a cache key to delete the cache by this key later?

For example, there is a request

$data = Yii::$app->DB->createCommand('SELECT * FROM customer WHERE id=1')->cache(3600)->queryAll();

How to assign a key to it, so that later it can be deleted by key:
Yii::$app->cache->delete($key1);
I tried using set - it didn’t work
$cache->set($key, $data, 45);

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Arman, 2018-06-19
@Arik

Alternatively, you can pass Dependency as the second argument

E
Evgeny Bukharev, 2018-06-19
@evgenybuckharev

: Associates the item's cached data with one or more tags. You can invalidate the caching of given elements with the given tag(s) on a call.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question