I have this method below that gives me a count of products within a category. I want to cache the count in my redis server. I am able to do that, but I am not sure how to bust the cache and my concept around that is not clear. Any help or ideas would be appreciated.
public static function products(){
$prods = $this>getProducts();
$Count = count($prods);
if($Count){
// save the count to redis
$redis->saveCount($count);
}
}
When do I hit the sql database ($prods = $this>getProducts();
) to get count, and when do I just get it from redis? Also, how would I know when to do it and when to bust the old records in redis?
Thanks