PHPackages                             silassiai/laravel-table-cache - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. silassiai/laravel-table-cache

ActiveLibrary

silassiai/laravel-table-cache
=============================

Solution to easily cache tables records, the package uses the laravel Cache facade.

02.7kPHP

Since Jan 2Pushed 3y ago1 watchersCompare

[ Source](https://github.com/Silassiai/laravel-table-cache)[ Packagist](https://packagist.org/packages/silassiai/laravel-table-cache)[ RSS](/packages/silassiai-laravel-table-cache/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

About laravel-table-cache (Work in progress)
--------------------------------------------

[](#about-laravel-table-cache-work-in-progress)

If you are working with a lot of data, it may not be best practice to work with collections (who are cached by laravel).

Instead of using (which returns a collection):

```
// for example in a cronjob that caches the users table
$users = cache()->rememberForever('users', function () {
    return DB::table('users')->pluck('email', 'id');
});
// when you need to check if this user exists somewhere later in your application
$users->where('email', 'john@do.nl')->exists();
```

We could do (which caches all the key values from the model directly in the cache):

```
// for example in a cronjob that caches the users table
User::cacheColumnKey('email')->withColumnValue('id');
// when you need to check if this user exists somewhere later in your application
User::cacheColumnKey('email')->isCached('john@do.nl');
// or if you need the value
User::cacheColumnKey('email')->getKeyValue('john@do.nl'); // returns the id in this case
```

Solution to easily cache tables records, the package uses the laravel Cache facade.

- Cache 2 table columns as key value pairs [Trait Key Value](#trait-key-value)

Installation
------------

[](#installation)

You can install the package via composer:

```
composer require silassiai/laravel-table-cache
```

Basic usage
-----------

[](#basic-usage)

### Trait Key Value

[](#trait-key-value)

You can add the `TableCacheKeyValueTrait` to you model to easily cache key value pairs (two columns) for your whole table. This can be handy when you want to cache the whole table after you seeded the model.

```
