renoki-co / laravel-eloquent-query-cache

Adding cache on your Laravel Eloquent queries' results is now a breeze.
Apache License 2.0
1.06k stars 118 forks source link

[4.x] Refactor #149

Closed rennokki closed 1 year ago

rennokki commented 2 years ago

Documentation WIP.

Removed newBaseQueryBuilder so it doesn't interfere with the model's query model

Cache properties are now all public

The $cache* properties and cache*Value() methods in your models should all public. Previously, they were protected.

Added cache global settings

Cache global settings can now be set at boot() or if you plan to use just the raw query builder with the DB facade.

For example, you can set base tags for all your Query Builder (not Eloquent) queries:

use Rennokki\QueryCache\QueryCache;

QueryCache::cacheBaseTags(['all']);

DB::table('posts')
    ->cacheQuery(3600)
    ->cacheTags(['all-posts'])
    ->get();

DB::table('posts')
    ->cacheQuery(3600)
    ->cacheTags(['older-posts'])
    ->older()
    ->get();

DB::flushQueryCache(); // will flush everything
DB::flushQueryCache(['older-posts']); // will flush just the second query

Cache key generation fingerprint

The way the cache key is generated is now different, to be more stable on a query-to-query basis. You can still use the previous key format by calling cacheUsePreviousKeyGenerationMethod in your AppServiceProvider's boot method:

use Rennokki\QueryCache\QueryCache;

QueryCache::cacheUsePreviousKeyGenerationMethod();

To be tested

Small improvements & changes

stale[bot] commented 2 years ago

This issue has been automatically closed because it has not had any recent activity. 😨

codecov[bot] commented 1 year ago

Codecov Report

Merging #149 (565ed19) into master (b0814fe) will increase coverage by 3.92%. The diff coverage is 92.35%.

Additional details and impacted files [![Impacted file tree graph](https://codecov.io/gh/renoki-co/laravel-eloquent-query-cache/pull/149/graphs/tree.svg?width=650&height=150&src=pr&token=bS4Bdkw9ok&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=renoki-co)](https://codecov.io/gh/renoki-co/laravel-eloquent-query-cache/pull/149?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=renoki-co) ```diff @@ Coverage Diff @@ ## master #149 +/- ## ============================================ + Coverage 83.52% 87.45% +3.92% - Complexity 0 101 +101 ============================================ Files 4 8 +4 Lines 170 271 +101 ============================================ + Hits 142 237 +95 - Misses 28 34 +6 ``` | [Impacted Files](https://codecov.io/gh/renoki-co/laravel-eloquent-query-cache/pull/149?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=renoki-co) | Coverage Δ | | |---|---|---| | [src/FlushQueryCacheObserver.php](https://codecov.io/gh/renoki-co/laravel-eloquent-query-cache/pull/149/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=renoki-co#diff-c3JjL0ZsdXNoUXVlcnlDYWNoZU9ic2VydmVyLnBocA==) | `53.57% <ø> (ø)` | | | [src/QueryBuilderWithCache.php](https://codecov.io/gh/renoki-co/laravel-eloquent-query-cache/pull/149/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=renoki-co#diff-c3JjL1F1ZXJ5QnVpbGRlcldpdGhDYWNoZS5waHA=) | `86.27% <86.27%> (ø)` | | | [src/RelationWithCache.php](https://codecov.io/gh/renoki-co/laravel-eloquent-query-cache/pull/149/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=renoki-co#diff-c3JjL1JlbGF0aW9uV2l0aENhY2hlLnBocA==) | `87.50% <87.50%> (ø)` | | | [src/EloquentBuilderWithCache.php](https://codecov.io/gh/renoki-co/laravel-eloquent-query-cache/pull/149/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=renoki-co#diff-c3JjL0Vsb3F1ZW50QnVpbGRlcldpdGhDYWNoZS5waHA=) | `89.28% <89.28%> (ø)` | | | [src/QueryCacheServiceProvider.php](https://codecov.io/gh/renoki-co/laravel-eloquent-query-cache/pull/149/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=renoki-co#diff-c3JjL1F1ZXJ5Q2FjaGVTZXJ2aWNlUHJvdmlkZXIucGhw) | `96.29% <96.29%> (ø)` | | | [src/QueryCache.php](https://codecov.io/gh/renoki-co/laravel-eloquent-query-cache/pull/149/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=renoki-co#diff-c3JjL1F1ZXJ5Q2FjaGUucGhw) | `100.00% <100.00%> (ø)` | | | [src/Traits/QueryCacheModule.php](https://codecov.io/gh/renoki-co/laravel-eloquent-query-cache/pull/149/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=renoki-co#diff-c3JjL1RyYWl0cy9RdWVyeUNhY2hlTW9kdWxlLnBocA==) | `91.66% <100.00%> (+0.26%)` | :arrow_up: | | [src/Traits/QueryCacheable.php](https://codecov.io/gh/renoki-co/laravel-eloquent-query-cache/pull/149/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=renoki-co#diff-c3JjL1RyYWl0cy9RdWVyeUNhY2hlYWJsZS5waHA=) | `100.00% <100.00%> (+18.91%)` | :arrow_up: | ------ [Continue to review full report at Codecov](https://codecov.io/gh/renoki-co/laravel-eloquent-query-cache/pull/149?src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=renoki-co). > **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=renoki-co) > `Δ = absolute (impact)`, `ø = not affected`, `? = missing data` > Powered by [Codecov](https://codecov.io/gh/renoki-co/laravel-eloquent-query-cache/pull/149?src=pr&el=footer&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=renoki-co). Last update [b0814fe...565ed19](https://codecov.io/gh/renoki-co/laravel-eloquent-query-cache/pull/149?src=pr&el=lastupdated&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=renoki-co). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=renoki-co).
stale[bot] commented 1 year ago

This issue has been automatically closed because it has not had any recent activity. 😨