public function count(): int
    {
        $query = $this->viewable->views();

        $cacheKey = Key::createForEntity($this->viewable, $this->period ?? Period::create(), $this->unique, $this->collection);

        if ($this->shouldCache) {
            $cachedViewsCount = $this->cache->get($cacheKey);

            // Return cached views count if it exists
            if ($cachedViewsCount !== null) {
                return (int) $cachedViewsCount;
            }
        }

        if ($period = $this->period) {
            $query->withinPeriod($period);
        }

        $query->where('collection', $this->collection);

        if ($this->unique) {
            $viewsCount = $query->uniqueVisitor()->count('visitor');
        } else {
            $viewsCount = $query->count();
        }

        if ($this->shouldCache) {
            $this->cache->put($cacheKey, $viewsCount, $this->cacheLifetime);
        }

        return $viewsCount;
    }
public function count(): int
    {
        $query = $this->viewable->views();

        $cacheKey = Key::createForEntity($this->viewable, $this->period ?? Period::create(), $this->unique, $this->collection);

        if ($this->shouldCache) {
            $cachedViewsCount = $this->cache->get($cacheKey);

            // Return cached views count if it exists
            if ($cachedViewsCount !== null) {
                return (int) $cachedViewsCount;
            }
        }

        if ($period = $this->period) {
            $query->withinPeriod($period);
        }

        $query->where('collection', $this->collection);

        if ($this->unique) {
            $viewsCount = $query->uniqueVisitor()->count('visitor');
        } else {
            $viewsCount = $query->count();
        }

        if ($this->shouldCache) {
            $this->cache->put($cacheKey, $viewsCount, $this->cacheLifetime);
        }

        return $viewsCount;
    }
public function count ( ) : int { $ query = $ this -> viewable -> views ( ) ; $ cacheKey = Key :: createForEntity ( $ this -> viewable , $ this -> period ?? Period :: create ( ) , $ this -> unique , $ this -> collection ) ; if ( $ this -> shouldCache ) { $ cachedViewsCount = $ this -> cache -> get ( $ cacheKey ) ; // Return cached views count if it exists if ( $ cachedViewsCount !== null ) { return ( int ) $ cachedViewsCount ; } } if ( $ period = $ this -> period ) { $ query -> withinPeriod ( $ period ) ; } $ query -> where ( 'collection' , $ this -> collection ) ; if ( $ this -> unique ) { $ viewsCount = $ query -> uniqueVisitor ( ) -> count ( 'visitor' ) ; } else { $ viewsCount = $ query -> count ( ) ; } if ( $ this -> shouldCache ) { $ this -> cache -> put ( $ cacheKey , $ viewsCount , $ this -> cacheLifetime ) ; } return $ viewsCount ; }
Count the views.

@return int
Count the views .