php - How to delete cakephp cached file by name or by name prefix?

653

In cakephp 2.0 I cache some information getting from some service calls in file for individual users. Using individual user_id as a prefix of the cached file name, I cache the files under a custom cache configuration which saves in a folder under cache folder.

Like, if the service name is get_user_info and the custom cache folder name is user_info then for a user say user_id:111, a file will be cached with name 111_get_user_info in cache/user_info.

If I need to remove the cached info for this user:111, I can't make that. Because Cache::clear(false, 'user_info') deletes all the cached files under cache/user_info and as a consequence other users cached info has removed as well.

Can anybody suggest me how can I clear the cached file by using a prefix match?

Thanks!

606

Answer

Solution:

Any reasondelete wouldn't work?

Cache::delete($key);

?

ref: http://book.cakephp.org/2.0/en/core-libraries/caching.html#CacheEngine::delete

890

Answer

Solution:

You can use the functionclearCache($file) where $file need to be some like that:

$file = "myprefix_the_complete_name_with_extension.php";

you need to create the entire path to pass a cake.

keep me posted if this solution work for you.

Best Regards.

People are also looking for solutions to the problem: c# - What design pattern to use for grouping report queries

Source

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.