Giter Site home page Giter Site logo

00f100 / fcphp-cache Goto Github PK

View Code? Open in Web Editor NEW
2.0 1.0 1.0 32 KB

Package to manage Cache Index and crypto content using Sodium PHP (optional)

License: MIT License

PHP 100.00%
cache cache-storage crypto sodium-library libsodium php7 php72 redis

fcphp-cache's Introduction

FcPhp Cache

Package to manage Cache Index and crypto content using Sodium PHP (optional)

Build Status codecov Total Downloads

How to install

Composer:

$ composer require 00f100/fcphp-cache

or add in composer.json

{
    "require": {
        "00f100/fcphp-cache": "*"
    }
}

How to use

<?php

use FcPhp\Cache\Facades\CacheFacade;
use FcPhp\Crypto\Crypto;

/**
 * Method to create new instance of Cache
 *
 * @param string|array $cacheRepository Configuration of redis or path to save files cache
 * @param string $nonce Nonce to use crypto into content of cache. To generate: \FcPhp\Crypto\Crypto::getNonce()
 * @param string $pathKeys Path to save keys crypto
 * @return FcPhp\Cache\Interfaces\ICache
 */
$cache = CacheFacade::getInstance(string|array $cacheRepository, string $nonce = null, string $pathKeys = null);

/*
    To use with Redis
    =========================
*/
$redis = [
    'host' => '127.0.0.1',
    'port' => '6379',
    'password' => null,
    'timeout' => 100,
];
$cache = CacheFacade::getInstance($redis);
/*
    To use with Redis and crypto
    =========================
*/
$redis = [
    'host' => '127.0.0.1',
    'port' => '6379',
    'password' => null,
    'timeout' => 100,
];
$cache = CacheFacade::getInstance($redis, Crypto::getNonce(), 'path/to/keys');

/*
    To use with file
    =========================
*/
$cache = CacheFacade::getInstance('path/to/cache');

/*
    To use with file and crypto
    =========================
*/
$cache = CacheFacade::getInstance('path/to/cache', Crypto::getNonce(), 'path/to/keys');

/**
 * Method to create new cache
 *
 * @param string $key Key to name cache
 * @param mixed $content Content to cache
 * @param int $ttl time to live cache
 * @return FcPhp\Cache\Interfaces\ICache
 */
$cache->set(string $key, $content, int $ttl) :ICache

/**
 * Method to verify if cache exists
 *
 * @param string $key Key to name cache
 * @return bool
 */
$cache->has(string $key) :bool

/**
 * Method to verify/read cache
 *
 * @param string $key Key to name cache
 * @return mixed
 */
$cache->get(string $key)

/**
 * Method to delete cache
 *
 * @param string $key Key to name cache
 * @return void
 */
$cache->delete(string $key) :void

/**
 * Method to clean old caches
 *
 * @return FcPhp\Cache\Interfaces\ICache
 */
$cache->clean() :ICache

fcphp-cache's People

Contributors

00f100 avatar

Stargazers

 avatar  avatar

Watchers

 avatar

Forkers

dashbaord202401

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.