rinvex/laravel-addresses

Cache Question

Closed this issue · 1 comments

Great package!
Thank you for putting your time into this project and sharing it freely.

I'm struggling to clear the specific address cache on address update.
Currently, I'm reduced to:

\Cache::forget('81ca4acffc20c7eacc78cf266025017b');

Getting the keyId from app/storage/framework/cache/data/rinvex.cacheable.json and hard-coding it into my update() method, which works, but is obviously not a viable solution.

Do you have any suggestions?

Edit:
I have extended the Address model and added a function that I can call to remove all the cached keys, but I would like some way of targeting only the address that was just updated rather than clearing the whole cache:

    public static function clearcache()
    {
        $string = file_get_contents("../storage/framework/cache/data/rinvex.cacheable.json");
        $json_a = json_decode($string, true);
        foreach ($json_a as $key => $value) {
            if($key == "App\Address"){
                foreach($value as $id){
                    \Cache::forget($id);
                }
            }
        }
    }

Is there a way I can identify which key is appropriate for a specific user?

Thank you for the valuable feedback, and sorry for the delayed reply!

Upon further discussions about caching, we dropped caching from the core packages for more flexibility, and to leave it's responsibility for the application layer. Check recent commit 07d45a5