Giter Club home page Giter Club logo

laravel-cacheable's Introduction

Rinvex Cacheable

⚠️ This package is abandoned and no longer maintained. No replacement package was suggested. ⚠️

👉 If you are interested to step on as the main maintainer of this package, please reach out to me!


Rinvex Cacheable is a granular, intuitive, and fluent caching system for eloquent models. Simple, but yet powerful, plug-n-play with no hassle.

Packagist Scrutinizer Code Quality Travis StyleCI License

What this package do -technically- caching eloquent query passing through the get method, whatever it is and it's smart enough to indicated any conditions, limit, offset, wheres, orders, groups, ..etc and take that criteria into account when caching and checking for cached version. Also by default any create, update, or delete event will flush all cache for that specific model. It uses default Laravel caching system, and utilizes whatever cache driver you are using. Awesome, right?

Installation & Usage

  1. Install the package via composer:

    composer require rinvex/laravel-cacheable
  2. Use the \Rinvex\Cacheable\CacheableEloquent in your desired model, and you're done!

  3. Seriously, that's it!

Check the CacheableEloquent source code for more awesome stuff if you need advanced control.

Optional Features

You can optionally override model caching behaviour per model as follows:

    /**
     * Indicate if the model cache clear is enabled.
     *
     * @var bool
     */
    protected $cacheClearEnabled = true;

    /**
     * The model cache driver.
     *
     * @var string
     */
    protected $cacheDriver = 'memcached';

    /**
     * The model cache lifetime.
     *
     * @var int
     */
    protected $cacheLifetime = -1;

Changelog

Refer to the Changelog for a full history of the project.

Support

The following support channels are available at your fingertips:

Contributing & Protocols

Thank you for considering contributing to this project! The contribution guide can be found in CONTRIBUTING.md.

Bug reports, feature requests, and pull requests are very welcome.

Security Vulnerabilities

If you discover a security vulnerability within this project, please send an e-mail to [email protected]. All security vulnerabilities will be promptly addressed.

About Rinvex

Rinvex is a software solutions startup, specialized in integrated enterprise solutions for SMEs established in Alexandria, Egypt since June 2016. We believe that our drive The Value, The Reach, and The Impact is what differentiates us and unleash the endless possibilities of our philosophy through the power of software. We like to call it Innovation At The Speed Of Life. That’s how we do our share of advancing humanity.

License

This software is released under The MIT License (MIT).

(c) 2016-2021 Rinvex LLC, Some rights reserved.

laravel-cacheable's People

Contributors

mohamed-hendawy avatar omranic avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

laravel-cacheable's Issues

Overriding $cacheLifetime

Hi!

I'm using this trait in a model where the default lifetime of -1 doesn't make sense, so I'm trying to change it to another number by adding protected $cacheLifetime = 10; into my class definition. However, it keeps FatalErrorException:ing on me and spitting back: App\Model\<myModel> and Rinvex\Cacheable\CacheableEloquent define the same property ($cacheLifetime) in the composition of App\Model\<myModel>..

Any suggestions?

Doesn't work with factories

When running factories, the data will be empty:

<?php

namespace Database\Seeders\Pages;

use App\Pages\Entities\Page;
use Illuminate\Database\Seeder;
use Illuminate\Database\Eloquent\Model;

class PagesTableSeeder extends Seeder
{
    /**
     * Run the database seeds.
     *
     * @return void
     */
    public function run()
    {
        Model::unguard();

        factory(Page::class, 500)->create();

        //Page::forgetCache();

        dd(Page::all());
    }
}

this will return an empty collection even though there's rows in the database.

How to disable cache for RAND()

I have a query builder using inRandomOrder() method.
But this cache the result. I want ignore cache if have RAND() query.

$posts = Post::inRandomOrder()->take(10)->get();

Set cache driver and cache lifetime

Hi. Not really an issue but I'm not figuring out how to set cache driver and cache lifetime.
The cache works ok with the default cache driver.

Thanks in advance

Cached relations are not invalidated

CacheableEloquent caches relations data, but does not invalidate cache when the related models change. There is no indications in the documentation of how relationships are treated or if there are strategies to make caching work for relations.

getCacheLifetime return type error

Type error: Return value of Rinvex\Attributes\Models\AttributeEntity::getCacheLifetime() must be of the type integer, null returned

because

    public function getCacheLifetime(): int
    {
        return $this->cacheLifetime;
    }
    public function resetCacheConfig()
    {
        $this->cacheDriver = null;
        $this->cacheLifetime = null;

        return $this;
    }

set cacheLifetime to null

Forget cache all models

Hi, I have a process that makes a lot of changes.

How can I forget all models cache?

Thanks!

Question: Should work on PHP 5.6 ?

Hi, this seems to be great package !

Are you planning to support 5.6+ version of PHP. I am running LV 5.3 but wasn't able to install this on it because it enforces v7 of php.

Thanks

data folder inside framework/cache/ not created after cache:clear

Hi,

i have a question regarding writing the rinvex.cacheable.json file into the cache folder.

My Setup:

I basically got the rinvex/attributable package loaded and the rinvex/cacheable is used through it.

Problem:

Whenever you run artisan cache:clear and run anything afterwards like calling a controller that loads a model implementing the attributable behavior, creating the cache file fails.

file_put_contents(/Users/.../storage/framework/cache/data/rinvex.cacheable.json): failed to open stream: No such file or directory
```

The referring Code is in `cacheable/src/CacheableEloquent.php:99`
```
protected static function storeCacheKey(string $modelName, string $cacheKey)
    {
        $keysFile = storage_path('framework/cache/data/rinvex.cacheable.json');
        $cacheKeys = static::getCacheKeys($keysFile);
        if (! isset($cacheKeys[$modelName]) || ! in_array($cacheKey, $cacheKeys[$modelName])) {
            $cacheKeys[$modelName][] = $cacheKey;
            file_put_contents($keysFile, json_encode($cacheKeys));
        }
    }
```

Actually if the data folder inside framework/cache is not present creating the file will fail.
Manually creating the folder and everything is fine.

My Question
---------------
Shall i provide a PullRequest that simply checks if the folder exists and creates it?

Best
null9beta

laravel 5.5: Your requirements could not be resolved to an installable set of packages.

There is no support for 5.5?

Problem 1
    - Installation request for rinvex/subscriptions dev-develop -> satisfiable by rinvex/subscriptions[dev-develop].
    - rinvex/subscriptions dev-develop requires rinvex/cacheable dev-develop -> satisfiable by rinvex/cacheable[dev-develop] but these conflict with your requirements or minimum-stability.

I also tried to install v0.0.2 same problem.

Any advice?
Thanks a lot in advance.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.