GithubHelp home page GithubHelp logo

laravel-mongodb-cache's Introduction

Laravel Mongodb Cache driver

A MongoDB cache driver for Laravel

Laravel
Version
Package
Version
Install using
this command
11.x 7.x.x composer require 1ff/laravel-mongodb-cache:^7.0
10.x 6.x.x composer require 1ff/laravel-mongodb-cache:^6.0
9.x 5.x.x composer require 1ff/laravel-mongodb-cache:^5.0
8.x 4.x.x composer require 1ff/laravel-mongodb-cache:^4.1
7.x 3.x.x composer require 1ff/laravel-mongodb-cache:^3.1
5.8.x, 6.x 2.12.x composer require 1ff/laravel-mongodb-cache:~2.12.0
5.7.x 2.11.x composer require 1ff/laravel-mongodb-cache:~2.11.0

Installation

Install using composer:

composer require 1ff/laravel-mongodb-cache

If you are using Laravel older than 5.5 add the service provider in config/app.php:

'ForFit\Mongodb\Cache\ServiceProvider::class',

Add the mongodb cache store in config/cache.php

'stores' => [
    ...

    'mongodb' => [
        'driver' => 'mongodb',
        'table' => 'cache', // name it as you wish
        'connection' => 'mongodb',
    ],
],

Add the mongodb database connection in config/database.php

'connections' => [
    ...

    'mongodb' => [
        'driver' => 'mongodb',
        'dsn' => env('MONGODB_DSN'),
        'database' => env('MONGODB_DATABASE'),
    ],
],

Update your .env file and change the CACHE_DRIVER to mongodb

CACHE_DRIVER=mongodb
MONGODB_DSN=mongodb://localhost:27017/laravel
MONGODB_DATABASE=laravel

Advantages

  • This driver uses the MongoDB TTL indexes meaning when a cache key expires it will be automatically deleted.

  • This way, the collection's size will remain around the size you expect and won't get falsely filled with unused data.

  • The package automatically adds a migration which creates the index by running a mongodb command.

  • This package also registers two new commands:

      php artisan mongodb:cache:index
    

    and

      php artisan mongodb:cache:dropindex
    

Warning

This cache driver is not compatible with other cache drivers because it encodes the data differently. If you are using another mongodb cache driver at the moment make sure you set a new collection for this one.

Enjoy!

laravel-mongodb-cache's People

Contributors

koprinski avatar spont4e avatar t1sh0o avatar tuseto avatar vcrazy avatar

Stargazers

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

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

laravel-mongodb-cache's Issues

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.