Skip to content

Best location to add cache for API get requests #269

@ssglopes

Description

@ssglopes

Hi,
Using this package for api request. Trying to add caching to reduce DB lookups with this package LaraGear CacheQuery. Could you maybe recommend where in your package this would be best added.
For example to cache all posts to redis something like this needs to be added somewhere in your code: Post::cache(null, Post::class). Tried to find the best place but so far without luck. I looked into adding a scope but it fails with an error:

class Server extends BaseServer {
......
public function serving(): void
    {
        ....
        Post::addGlobalScope(new CacheScope());
       .....

The CacheScope:

class CacheScope implements Scope
{
    public function apply(Builder $builder, Model $model)
    {
        // cache indefinite with key App\Models\Post
        $builder->cache(null, $model::class);
    }
}

The error i get: Lost connection and no reconnector available.

Any recommendation or hints in the right direction would be much appreciated.

Thanks.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions