permafrost-dev/laravel-scriptcache

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

Allows client-side scripts to leverage the server's laravel cache

1.0.0 2019-08-12 10:17 UTC

This package is auto-updated.

Last update: 2021-07-06 01:29:42 UTC


README

This package allows javascript to leverage the laravel cache and store small amounts of data for a limited amount of time, usually 60 seconds.

Installation

You can install the package via composer:

composer require permafrost-dev/laravel-scriptcache

Usage

    async function setCachedData(value) {
        const token = await axios.get('/api/scriptcache?data=' + value);
        return token;
    }

    async function getCachedData(token) {
        const result = (await axios.get('/api/scriptcache/'+token));
        return result;
    }

    async function doSomeDataProcessing(dataStr) {
        const token = (await setCachedData(dataStr)).data;
        const cacheid = token.cache_id;

        const cachedDataObject = (await getCachedData(cacheid)).data;
        const cachedData = cachedDataObject.data;

        console.log('original data: ', dataStr);
        console.log('got cached data: ', cachedData);
    }
    
    //...cache expires after 60 seconds

Notes

The cached data is sanitized prior to storage, and the cache key used is tied to the requesting user to avoid access to other items in the cache.

Testing

composer test

License

The MIT License (MIT). Please see License File for more information.