Code Monkey home page Code Monkey logo

cache's Introduction

Cache System

Why use it?

Manage your cache easily. This package is useful for better managing the File or Redis cache. Implements the functions for creating and returning caches using json-encoded serialization to make the cache transportable and usable by other external microservices.

Install & Configuration
composer require kosmosx/cache

You must enter the following provider in the bootstrap/app.php file: Uncomment the function

$app->withFacades();

Load configuration in boostrap file

$this->configure('cache');
$this->configure('database');

Or publish config in your Service Provider

$this->publishes([
    'Kosmosx/Cache/config/cache.php' => config_path('cache.php')
], 'config');

$this->publishes([
    'Kosmosx/Cache/config/database.php' => config_path('database.php')
], 'config');

Register service provider

$app->register(Kosmosx\Cache\CacheServiceProvider::class);

Documentation

Once you have cofigured using it:

$factory = app('factory.cache');            //return CacheFactory
$builderFile = $factory->file();            //return FileBuilder
$builderRedis = $factory->redis();          //return RedisBuilder
    
$file = app('service.cache.file');          //FileCommand
$redis = app('service.cache.redis');        //RedisCommand

SET

//If you use builder obj  
$builderRedis->default()->set($key, $value, $ttl);          //build FileCommand with DefaultSerializer and set cache
$builderRedis->response()->set($response, $value, $ttl);
$builderRedis->collect()->set($collect, $value, $ttl);

//With services 
$file->set($key, $value, $ttl);
$redis->set($key, $value, $ttl);

SET MANY

//array example: ["key" => $value, "key2" => $value2 ...]
//$ttl for all values

$builderFile->default()->setMany(array $values, $ttl);

$file->setMany(array $values, $ttl);
$redis->setMany(array $values, $ttl);

GET

$file->get($key, $serializer);
$redis->get($key, $serializer);

GET MANY

//array example: ["key", "key2", "keyN" ...]

$file->getMany(array $keys);
$redis->getMany(array $keys);

SERIALIZER

All data stored in cache (redis / file) are serialized with the json coding, so as to make them transportable by other languages. it is possible to use typed serializers, so that when it is recovered it is possible to reconstruct the initial object.

//Serializer 
ResponseSerializer()  //If you want cache Response object 
CollectSerializer()   //If you want cache Collect object 
DefaultSerializer()   //default cache

...->setSerializer(new ResponseSerializer());

Own Serializer

If you want to create your own serializer, just create a class that extends SerializerAbstract

use Kosmosx\Cache\Serializer\Abstracts\Serializer;
use Kosmosx\Cache\Serializer\Interfaces\SerializerInterface;
    
class {name} extends Serializer implements SerializerInterface

Other function

 //Use class cache manager 
 ...->manager()	//return istance of Illuminate/Redis or CacheManager     
 
 ...->forget(string $keys)
 ...->forgetMany(array $keys)
 
 ...->setAutodetect($bool)
 ...->getAutodetect()
 
 ...->clear()

cache's People

Contributors

fabriziocafolla avatar lasserafn avatar

Stargazers

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

Watchers

 avatar  avatar  avatar  avatar

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.