增加访问记录功能

This commit is contained in:
2023-06-28 11:12:30 +08:00
parent a12cca37e4
commit 65e1800c6f
18 changed files with 447 additions and 98 deletions

View File

@@ -23,6 +23,9 @@ class Post extends Base
use SoftDelete;
//
public const CACHE_KEY_HITS = 'cache_hits_';
public static $autoClearCache = [
[
'name' => 'top_post'
@@ -184,7 +187,7 @@ class Post extends Base
public function getPosterAttr($value)
{
if (empty($value)) {
$value = '/static/images/avatar.jpeg';
$value = '/static/images/avatar.png';
}
return get_source_link($value);
@@ -233,4 +236,31 @@ class Post extends Base
}
return $end_content;
}
public function getHitsTitleAttr()
{
$cache_key = static::CACHE_KEY_HITS.$this->getAttr('id');
$value = Cache::get($cache_key);
if(!is_null($value)) {
return $value;
}
$value = $this->getData('hits');
Cache::set($cache_key, $value, 600);
return $value;
}
public function setHitsAttr($value)
{
$cache_key = static::CACHE_KEY_HITS.$this->getAttr('id');
$this->getAttr('hits_title');
Cache::inc($cache_key);
return $value;
}
}