Git Product home page Git Product logo

counter-cache's Introduction

Counter Cache

⚠️This package is deprecated⚠️

Brings the ruby concept of "counter caching" to Laravel.

Total downloads Monthly downloads Latest release Open issues License Star repository on GitHub Watch repository on GitHub Fork repository on GitHub StyleCI

📝 Introduction

One thing we at Nodes have been missing in Laravel is the concept of "counter caching".

Laravel comes "out of the box" with the increment/decrement methods on it's Eloquent models. But you'll need to manually execute these methods everytime, you've saved/delete stuff with your model.

Since the increment/decrement methods always +1/-1, you can't 100% rely on these as cached value. What if you forgot to execute the decrement method when you deleted a row. Or what if someone deleted a row directly from the database, then your count would be "out of sync".

Therefore we've created this package which brings "counter caching" to Laravel.

The difference between this package and Laravel's increment/decrement is that our package actually generates and fires a SQL count statement, that counts the entries and updates the desired column with the result.

This way you're always 100% sure that the value in your "counter cache" column is correct.

📦 Installation

To install this package you will need:

  • Laravel 5.1+
  • PHP 5.5.9+

You must then modify your composer.json file and run composer update to include the latest version of the package in your project.

"require": {
    "nodes/counter-cache": "^1.0"
}

Or you can run the composer require command from your terminal.

composer require nodes/counter-cache:^1.0

⚙ Usage

Please refer to the Wiki documentation for more information.

🏆 Credits

This package is developed and maintained by the PHP team at Nodes Agency

Follow Nodes PHP on Twitter Tweet Nodes PHP

📄 License

This package is open-sourced software licensed under the MIT license

counter-cache's People

Contributors

carmenioanamihaila avatar casperhr avatar fadugyamfi avatar mdemblani avatar rugaard avatar zeneo avatar

Stargazers

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

Watchers

 avatar  avatar  avatar  avatar

counter-cache's Issues

composer installation fails with error

Hi. I tried installing counter-cache into Laravel 5.2.32 without success. Command used:

$ composer require nodes/counter-cache

Result:

Installation failed, reverting ./composer.json to its original content.
[ErrorException]                                
dirname() expects exactly 1 parameter, 2 given

I know little about how composer works so unfortunately I cannot suggest a solution.

Would it be possible to get some basic information on how to set up and use the plugin?

Cheers.

[Request] Add command to update all relation counts

Hey,

found this package to avoid many queries. If you implement this package in the middle of your project there should be a artisan command to count all relations and store them in the specified column.

Just an idea... 😄

Laravel 5.7 support

Can the composer.json be updated to provide support for laravel 5.7 or basically remove the restrictions?

Counter-Cache for Composite Key

There is a Laravel Package called Compoships, which provides support for composite keys in relations. When a model using a Compoship relation i.e. composite key relation is used in Counter-Cache, the counter-cache update method returns an error of array being converted to string, indicating that composite key counter-cache is not supported

Install error Laravel 5.4

Package cannot be installed within a Laravel 5.4 app:

#composer require nodes/counter-cache:^2.0

Problem 1
    - nodes/core 1.0.1 requires laravel/framework 5.1.*||5.2.* -> satisfiable by laravel/framework[5.1.x-dev, 5.2.41, 5.2.x-dev, v5.1.0, v5.1.1, v5.1.10, v5.1.11, v5.1.12, v5.1.13, v5.1.14, v5.1.15, v5.1.16, v5.1.17, v5.1.18, v5.1.19, v5.1.2, v5.1.20, v5.1.21, v5.1.22, v5.1.23, v5.1.24, v5.1.25, v5.1.26, v5.1.27, v5.1.28, v5.1.29, v5.1.3, v5.1.30, v5.1.31, v5.1.32, v5.1.33, v5.1.34, v5.1.35, v5.1.36, v5.1.37, v5.1.38, v5.1.39, v5.1.4, v5.1.40, v5.1.41, v5.1.42, v5.1.43, v5.1.44, v5.1.45, v5.1.46, v5.1.5, v5.1.6, v5.1.7, v5.1.8, v5.1.9, v5.2.0, v5.2.0-beta1, v5.2.1, v5.2.10, v5.2.11, v5.2.12, v5.2.13, v5.2.14, v5.2.15, v5.2.16, v5.2.17, v5.2.18, v5.2.19, v5.2.2, v5.2.20, v5.2.21, v5.2.22, v5.2.23, v5.2.24, v5.2.25, v5.2.26, v5.2.27, v5.2.28, v5.2.29, v5.2.3, v5.2.30, v5.2.31, v5.2.32, v5.2.33, v5.2.34, v5.2.35, v5.2.36, v5.2.37, v5.2.38, v5.2.39, v5.2.4, v5.2.40, v5.2.42, v5.2.43, v5.2.44, v5.2.45, v5.2.5, v5.2.6, v5.2.7, v5.2.8, v5.2.9] but these conflict with your requirements or minimum-stability.
    - nodes/core 1.0.0 requires laravel/framework 5.1.*||5.2.* -> satisfiable by laravel/framework[5.1.x-dev, 5.2.41, 5.2.x-dev, v5.1.0, v5.1.1, v5.1.10, v5.1.11, v5.1.12, v5.1.13, v5.1.14, v5.1.15, v5.1.16, v5.1.17, v5.1.18, v5.1.19, v5.1.2, v5.1.20, v5.1.21, v5.1.22, v5.1.23, v5.1.24, v5.1.25, v5.1.26, v5.1.27, v5.1.28, v5.1.29, v5.1.3, v5.1.30, v5.1.31, v5.1.32, v5.1.33, v5.1.34, v5.1.35, v5.1.36, v5.1.37, v5.1.38, v5.1.39, v5.1.4, v5.1.40, v5.1.41, v5.1.42, v5.1.43, v5.1.44, v5.1.45, v5.1.46, v5.1.5, v5.1.6, v5.1.7, v5.1.8, v5.1.9, v5.2.0, v5.2.0-beta1, v5.2.1, v5.2.10, v5.2.11, v5.2.12, v5.2.13, v5.2.14, v5.2.15, v5.2.16, v5.2.17, v5.2.18, v5.2.19, v5.2.2, v5.2.20, v5.2.21, v5.2.22, v5.2.23, v5.2.24, v5.2.25, v5.2.26, v5.2.27, v5.2.28, v5.2.29, v5.2.3, v5.2.30, v5.2.31, v5.2.32, v5.2.33, v5.2.34, v5.2.35, v5.2.36, v5.2.37, v5.2.38, v5.2.39, v5.2.4, v5.2.40, v5.2.42, v5.2.43, v5.2.44, v5.2.45, v5.2.5, v5.2.6, v5.2.7, v5.2.8, v5.2.9] but these conflict with your requirements or minimum-stability.
    - Conclusion: remove laravel/framework v5.4.32
    - Conclusion: don't install laravel/framework v5.4.32

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.