PHPackages                             rodrigopedra/file-tagged-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. [Caching](/categories/caching)
4. /
5. rodrigopedra/file-tagged-cache

ActiveLibrary[Caching](/categories/caching)

rodrigopedra/file-tagged-cache
==============================

File Tagged Cache Driver for Laravel

v1.3.0(3y ago)2182MITPHPPHP ^7.4|~8.0|~8.1

Since Feb 26Pushed 3y ago1 watchersCompare

[ Source](https://github.com/rodrigopedra/file-tagged-cache)[ Packagist](https://packagist.org/packages/rodrigopedra/file-tagged-cache)[ RSS](/packages/rodrigopedra-file-tagged-cache/feed)WikiDiscussions master Synced 2d ago

READMEChangelog (4)Dependencies (3)Versions (5)Used By (0)

File Tagged Cache Driver for Laravel
====================================

[](#file-tagged-cache-driver-for-laravel)

This package provides support for Tagged Cache using the file driver for Laravel

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

[](#installation)

```
composer require rodrigopedra/file-tagged-cache

```

Configuration
-------------

[](#configuration)

After installation, you can configure a new cache store in your project's `./config/cache.php` file and use `file-tagged` as the cache driver.

```
// ./config/cache.php

'stores' => [
    // ...

    'posts' => [
        'driver' => 'file-tagged', // custom driver added by this package
        'path' => storage_path('framework/cache/posts'),
    ],
],
```

### Storage folder

[](#storage-folder)

If you are using a custom directory to store you cache data, it is a good idea to create that directory beforehand and list it in the relevant `.gitignore` files.

For example, the snippet above configures the cache data to be stored inside the `./storage/framework/cache/posts`directory.

As this directory does not exist in your default Laravel installation, you need to create it.

For example:

```
./storage
├── app
├── framework
│   ├── cache
│   │   ├── data
│   │   │   └── .gitignore
│   │   ├── posts
│   │   │   └── .gitignore
│   │   └── .gitignore
│   ├── .gitignore
│   ├── sessions
│   ├── testing
│   └── views
└── logs

```

We added a new `/posts` directory inside the `./storage/framework/cache/` directory.

The `.gitgnore` file inside `./storage/framework/cache/data` should be kept the same as shipped by Laravel.

The `.gitgnore` file inside `./storage/framework/cache/posts` should be configured as below:

```
*
!.gitignore
```

The `.gitignore` file inside `./storage/framework/cache` (parent directory of both `/data` and `/posts`) should be changed to allow the created `/posts` directory, as below:

```
*
!data/
!posts/
!.gitignore
```

Usage
-----

[](#usage)

You can use the `Cache` façade to get an instance of this custom store and use it as any other Tagged Cache store shipped with Laravel.

```
use Illuminate\Support\Facades\Cache;

Cache::store('posts')->tags(['a-tag', 'another-tag'])->put('key', 'Hello World!');
```

If you are not familiar with how Tagged Cache works in Laravel, take a look in the related Laravel documentation about it:

Motivation
----------

[](#motivation)

This package was initially built to provide an easy way to cache views that are dependent on Eloquent models in servers where a more adequate tagged cache solution is unavailable.

Be aware this cache driver is aimed to be used in projects where content doesn't change very frequently and changes are made by few users (ideally one user) at a time.

If your project has a more dynamic nature, or allows many users to edit the same content at the same time, consider using one of the Tagged Cache drivers shipped with Laravel.

### Usage With Eloquent Models

[](#usage-with-eloquent-models)

***This section is entirely optional, the resources provided here do not interfere with the cache driver usage.***

This package provides an Observer, a Contract, and a Trait to make usage with Eloquent Models easier.

Let's consider a Blog project with 3 models: `Post`, `Author` and `Comment`.

We could add the Observer and Trait to the models as such:

```
