PHPackages                             linslin/laravel-coffee-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. linslin/laravel-coffee-cache

ActiveLaravel-extension[Caching](/categories/caching)

linslin/laravel-coffee-cache
============================

File based lever out cache for laravel. This cache hook in before composer autoload and Laravel boostrapping. It will push your application into light speed.

1.25.0(1y ago)82.7k2MITPHP

Since May 3Pushed 1y ago1 watchersCompare

[ Source](https://github.com/linslin/laravel-coffee-cache)[ Packagist](https://packagist.org/packages/linslin/laravel-coffee-cache)[ RSS](/packages/linslin-laravel-coffee-cache/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (1)Versions (48)Used By (0)

☕ laravel-coffee-cache
======================

[](#-laravel-coffee-cache)

[![Total Downloads](https://camo.githubusercontent.com/16c194e0f0f6f6effaf3a49e1ebb82fbb700837c41558c6e7fcdd1ea89a61e03/68747470733a2f2f706f7365722e707567782e6f72672f6c696e736c696e2f6c61726176656c2d636f666665652d63616368652f646f776e6c6f616473)](https://packagist.org/packages/linslin/laravel-coffee-cache)[![License](https://camo.githubusercontent.com/913910948de83fc3b9102a04a7c92c72e60654e86700bde6432e93bba2799fc1/68747470733a2f2f706f7365722e707567782e6f72672f6c696e736c696e2f6c61726176656c2d636f666665652d63616368652f6c6963656e7365)](https://packagist.org/packages/linslin/laravel-coffee-cache)

Store based lever out view cache for **Laravel 4.x, 5.x 6.x, 7.x, 8.x, 9.x, 10.x and 11.x**. This cache hook in before composer autoload and Laravel bootstrapping. It will push your application into light speed. By default, all GET-Requests will be cached.

It's a coffee cache. You can drink more coffee instead of spending time to optimize your application or server environment. Mokka Mokka!

Why and when should I use laravel-coffee-cache?
-----------------------------------------------

[](#why-and-when-should-i-use-laravel-coffee-cache)

Laravel getting bigger and bigger over the years. Today laravel is a very nice framework which helps you to speed up your software development and programming in its best way. On the other hand laravel is slow in handling requests and consumes a lot of memory per request, even if you use View or Database caches. The bootstrapping of laravel takes a bit time also it consumes a lot of memory. E.g. if you want to render an "imprint / disclaimer" page which doesn't have any dynamic data in its view. So, why you want to bootstrap laravel and all its dependencies just for returning a simple HTML page?

☕ **laravel-coffee-cache** allows you to lever out laravel and composer autoload completely once a cache file has been generated for a specific route (Request URI). In this way it consumes so much less hardware resources (CPU, RAM, Hard Disk) for each request. It will be push your application into light speed.

**The difference to existing cache systems for laravel is:** You don't need to have a DB cache based on memcached or even a view file based cache placed in a laravel middleware. **Hint:** It's nice approach is to combine your DB Cache with **laravel-coffee-cache**. Use your DB Cache even if you have **laravel-coffee-cache** running in the foreground.

You will be able to create highly frequented web applications and save a lot of hardware resources (which also saves money) with ☕ **laravel-coffee-cache**. It makes to optimize your applications if your website is too slow or your server / server capacities (CPU, Memory) run at full load. Give it a try.

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

[](#installation)

```
composer require --prefer-dist linslin/laravel-coffee-cache "*"

```

Register Facade
---------------

[](#register-facade)

If you want to use the facade to handle the cache files, add this to your facades in `config/app.php` in the `alias` array:

```
'CoffeeCache' => linslin\CoffeeCache\Facades\CoffeeCache::class,

```

Example `./config/coffeeCache.php` config file
----------------------------------------------

[](#example-configcoffeecachephp-config-file)

```
return [

    /**
     * Cache driver: 'file' or 'redis'
     */
    'driver' => 'file',

    /*
     * Redis connection
     */
    'redis' => [
        'host' => 'localhost',
        'port' => 6000,
        'password' => '', //leave empty if no password is given
        'timeout' => 0.5
    ],
];

```

API Documentation
-----------------

[](#api-documentation)

#### Initialize instance

[](#initialize-instance)

Should be placed in your `app/public/index.php` file.

```
$coffeeCache = new CoffeeCache(__DIR__);

```

#### Configure enabled hosts for caching \[optional\]

[](#configure-enabled-hosts-for-caching-optional)

Matching hosts which should be cached. Default: Cache all domains

```
$coffeeCache->enabledHosts = [
    'www.production.com',
    'subdomain.production.com',
];

```

#### Configure enabled hosts with sessions for caching \[optional\]

[](#configure-enabled-hosts-with-sessions-for-caching-optional)

Matching hosts which should be cached only if a cookie cached=1 is set. Default: Cache all domains

```
$coffeeCache->enabledCacheHostsWithSession = [
    'www.production.com',
    'subdomain.production.com',
];

```

#### Configure query parameters to exclude from request uri \[optional\]

[](#configure-query-parameters-to-exclude-from-request-uri-optional)

Matching query parameters are excluded from the request uri. A request uri with an excluded query param is treated like if the parameter is not set. Default: no query parameter is exclude

```
$coffeeCache->excludeQueryParam  = [
    'aQueryParameter',
];

```

#### Enable / disable the whole cache \[optional|default:true\]

[](#enable--disable-the-whole-cache-optionaldefaulttrue)

Flag for easy disabling the cache.

```
$coffeeCache->cacheEnabled = true;

```

#### Configure the cache driver (file, redis) \[optional|default:'file'|'redis'\]

[](#configure-the-cache-driver-file-redis-optionaldefaultfileredis)

```
$coffeeCache->cacheDriver = 'redis';
$coffeeCache->redisConnection = [
    'host' => 'localhost',
    'port' => 6000,
    'password' => '',
    'timeout' => 0.5
];

```

#### Configure HTTP-Status codes which should be cached \[optional\]

[](#configure-http-status-codes-which-should-be-cached-optional)

List of HTTP-Status codes which should be cached. Default: Cache "200" only.

```
$coffeeCache->enabledHttpStatusCodes = [
  '200',
  '202',
];

```

#### Exclude URL patterns from being cached. \[optional\]

[](#exclude-url-patterns-from-being-cached-optional)

URL patterns of URLs which should not be cache. This example will exclude URLS which have "/admin" somewhere in the URL.

```
$coffeeCache->excludeUrls = [
    '/admin',
];

```

#### Enable minify cache data \[optional\]

[](#enable-minify-cache-data-optional)

Strip whitespaces after tags, except space. Strip whitespaces before tags, except space. Shorten multiple whitespace sequences. Remove HTML comments

```
$coffeeCache->minifyCacheFile = true;

```

#### Enable cookie handled cache \[optional\]

[](#enable-cookie-handled-cache-optional)

The cache only will work if a cookie named "cached" is available and hold the value "1". This is for handling user sessions while running coffeeCache. It allows you to enable / disable cache for logged in users. Create a cookie with cached=1 if a user is not logged in. Create a cookie with cached=0 if a user is logged in.

```
$coffeeCache->cookieHandledCacheEnabled = true;

```

#### Enable compression \[optional\]

[](#enable-compression-optional)

Enable gzip compression for cache data. Default is `false`.

```
$coffeeCache->gzipEnabled = true;

```

#### Filter content types from being minified. \[optional\]

[](#filter-content-types-from-being-minified-optional)

Response content types which will be ignored and not minified.

```
$coffeeCache->minifyIgnoreContentTypes = [
    'image/png',
    'image/gif',
    'image/jpg',
    'image/jpeg',
];

```

#### Global replacements \[optional\]

[](#global-replacements-optional)

Will replace some string marker in our cached file. Which allows you to globally manipulate the cache data. You can parse a string or filepath. The file contents will replace the marker string.

```
$coffeeCache->globalReplacements = [
    [
        'type' => 'string',
        'marker' => '###marker1####',
        'value' => 'hallo welt'
    ], [
        'type' => 'file',
        'marker' => '###marker2####',
        'filePath' => __DIR__.'/../public/test.txt'
    ], [
        'type' => 'file',
        'marker' => '###start_marker####',
        'markerEnd' => '###end_marker####',
        'filePath' => __DIR__.'/../public/test.txt'
    ]
];

```

Facade API Documentation
------------------------

[](#facade-api-documentation)

### Delete all cache files

[](#delete-all-cache-files)

```
CoffeeCache::clearCache();

```

### Manually delete cache files

[](#manually-delete-cache-files)

```
CoffeeCache::clearCacheFile(route('route.name', [], false));

```

### Check if cache file exist

[](#check-if-cache-file-exist)

```
CoffeeCache::cacheFileExists(route('route.name', [], false));

```

### Get creation date (file driver only)

[](#get-creation-date-file-driver-only)

```
CoffeeCache::getCacheFileCreatedDate(route('route.name', [], false));

```

#### Example: Manually delete cache a specific file

[](#example-manually-delete-cache-a-specific-file)

E.g. inside a controller - example:

```
