diff --git a/CHANGELOG.md b/CHANGELOG.md index fd63dcb1..073176e7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,12 @@ All notable changes to `Eloquent Viewable` will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). +## [v6.0.2] + +### Fixed + +- Revert breaking change of `remember` method in `Views` contract. The `$lifetime` variable has now a default value of `null`. + ## [v6.0.1] ### Fixed diff --git a/README.md b/README.md index dff508df..8806f34c 100644 --- a/README.md +++ b/README.md @@ -380,7 +380,7 @@ protected $removeViewsOnDelete = true; Caching the views count can be challenging in some scenarios. The period can be for example dynamic which makes caching not possible. That's why you can make use of the in-built caching functionality. -To cache the views count, simply add the `remember()` method to the chain. +To cache the views count, simply add the `remember()` method to the chain. The default lifetime is forever. Examples: @@ -392,12 +392,15 @@ views($post)->period(Period::pastMonths(2))->remember()->count(); views($post)->period(Period::subHours(6))->remember()->count(); ``` -The default lifetime is configurable through the config file. Alternatively, you can pass a custom lifetime to the `remember` method. - ```php -views($post) - ->remember(now()->addHours(6)) - ->count(); +// Cache for 3600 seconds +views($post)->remember(3600)->count(); + +// Cache until the defined DateTime +views($post)->remember(now()->addWeeks(2))->count(); + +// Cache forever +views($post)->remember()->count(); ``` ## Optimizing diff --git a/UPGRADING.md b/UPGRADING.md index 0518b435..cffbb6ef 100644 --- a/UPGRADING.md +++ b/UPGRADING.md @@ -2,6 +2,7 @@ ## Table of contents +- [Upgrading from v6.0.1 to v6.0.2](#upgrading-from-v601-to-v602) - [Upgrading from v5.2.1 to v6.0.0](#upgrading-from-v521-to-v600) - [Upgrading from v5.2.0 to v5.2.1](#upgrading-from-v520-to-v521) - [Upgrading from v5.1.0 to v5.2.0](#upgrading-from-v510-to-v520) @@ -13,6 +14,14 @@ - [Upgrading from v2.0.0 to v2.1.0](#upgrading-from-v200-to-v210) - [Upgrading from v1.0.5 to v2.0.0](#upgrading-from-v105-to-v200) +## Upgrading from v6.0.1 to v6.0.2 + +There are no manual changes needed. + +## Upgrading from v6.0.0 to v6.0.1 + +There are no manual changes needed. + ## Upgrading from v5.2.1 to v6.0.0 ### Check requirements @@ -48,6 +57,12 @@ The parameters of the `orderByViews` query scope in the `Viewable` contract have +public function scopeOrderByUniqueViews(Builder $query, string $direction = 'desc', ?Period $period = null, ?string $collection = null, string $as = 'unique_views_count'): Builder; ``` +### The default cache lifetime has been changed + +The default cache lifetime functionality has been removed. The default value is now `null`, which means it will be cached forever. + +Look for all occurrences of the `remember` method and pass the desired lifetime. + ### Changes to the `Views` contract * The `$viewable` argument of the `forViewable` method cannot be `null` anymore. diff --git a/src/Contracts/Views.php b/src/Contracts/Views.php index e93c1dd1..c0c1cbfa 100644 --- a/src/Contracts/Views.php +++ b/src/Contracts/Views.php @@ -58,5 +58,5 @@ public function unique(bool $state = true): self; * * @param \DateTimeInterface|int|null $lifetime */ - public function remember($lifetime): self; + public function remember($lifetime = null): self; }