rinvex / laravel-repositories

⚠️ [ABANDONED] Rinvex Repository is a simple, intuitive, and smart implementation of Active Repository with extremely flexible & granular caching system for Laravel, used to abstract the data layer, making applications more flexible to maintain.
https://rinvex.com
MIT License
668 stars 115 forks source link

setCacheLifetime issue in multiple queries #167

Open rbruhn opened 6 years ago

rbruhn commented 6 years ago

Want to warn some users if they see something strange happening. When performing multiple queries on the same repo, same request, the setCacheLifetime remains in effect even if not set.

$repo->setCacheLifetime(0)
            ->whereNotNull('banner_file_name')
            ->limit($count)
            ->get($attributes);

The above will set the $this->cacheLifetime to zero, thus not caching.

$repo->whereHas('nfnWorkflows')
            ->orderBy('created_at', 'desc')
            ->limit(5)
            ->findAll($attributes);

Running another query on the same repo during the same request or script run, you might expect the above query to use the cache. However, it does not. Instead, the repo still sees the setCacheLifetime(0) and runs the query against the database. Since this package does not reset the cacheLifetime after each query, you have to do it manually by using setCacheLifetime(null) on the subsequent query.

rjsworking commented 6 years ago

Hi @rbruhn

The same is true for setCacheDriver

Cheers