PHPackages                             joostvanveen/laravel-litespeedcache - 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. joostvanveen/laravel-litespeedcache

ActiveLibrary[Caching](/categories/caching)

joostvanveen/laravel-litespeedcache
===================================

Laravel implementation of joostvanveen/litespeedcache.

v1.3.0(7y ago)6233MITPHPPHP &gt;=7.1

Since Apr 22Pushed 7y ago1 watchersCompare

[ Source](https://github.com/joostvanveen/laravel-litespeedcache)[ Packagist](https://packagist.org/packages/joostvanveen/laravel-litespeedcache)[ RSS](/packages/joostvanveen-laravel-litespeedcache/feed)WikiDiscussions master Synced today

READMEChangelog (1)Dependencies (3)Versions (12)Used By (0)

[![coverage](https://camo.githubusercontent.com/b62b8ce8fd361c0594ae320997d99a7ef83088157100afe8de3f14f5680b3f61/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f636f7665726167652d3130302532352d79656c6c6f77677265656e2e7376673f63616368655365636f6e64733d33363030)](https://camo.githubusercontent.com/b62b8ce8fd361c0594ae320997d99a7ef83088157100afe8de3f14f5680b3f61/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f636f7665726167652d3130302532352d79656c6c6f77677265656e2e7376673f63616368655365636f6e64733d33363030)

joostvanveen/laravel-litespeedcache
===================================

[](#joostvanveenlaravel-litespeedcache)

A Laravel wrapper for joostvanveen/litespeedcache. If you wish to use Litespeed Cache outside of Laravel check out this framework agnostic

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

[](#installation)

Require the package using composer:

```
composer require joostvanveen/laravel-litespeedcache

```

Enable the Litespeed in your .htaccess file.

```

    # Enable public cache
    CacheEnable public /

    # Enable private cache if you need to
    CacheEnable private /

    # Check the public cache
    CacheLookup public on

    # Ignore normal Cache Control headers
    CacheIgnoreCacheControl On

    # Maximum expiration time in seconds
    CacheMaxExpire 604800

```

Usage
-----

[](#usage)

This package adds a `LitespeedCache` cache facade for easy use and sets middleware that automatically caches all requests, according to the config settings.

You can set which URLs (for instance any `adminconsole*`) and query strings not to cache in config. If you want to preview a page without cache, simply add `?cache_bypass=1` to a URL, or set a `cache_bypass` cookie with a vale of 1.

If you want to set your own middleware, you can set the package to **not** use the default middleware.

### Configuration

[](#configuration)

To be able to adjust the configuration for this package, publish the configuration files to your project's `/config` folder like so:

```
php artisan vendor:publish --provider="Joostvanveen\LaravelLitespeedcache\LitespeedCacheServiceProvider" --tag=config
```

The config file adds the following settings to your Laravel configuration:

```
// Cache is enabled
config(['litespeedcache.defaults.enabled' => true]);

// ESI is enabled
config(['litespeedcache.defaults.esiEnabled' => true]);

// Whether or not to cache ajax calls
config(['litespeedcache.defaults.enable_ajax_cache' => false]);

// Array of request methods that should be cached
config(['litespeedcache.defaults.cache_http_verbs' => ['GET', 'HEAD']]);

// Whether or not to use the deafult middleware that comes with this package
config(['litespeedcache.defaults.use_middleware' => true]);

// Default cache type
config(['litespeedcache.defaults.type' => 'public']);

// Default TTL for cache in minutes
config(['litespeedcache.defaults.lifetime' => 240]);

// Array of URIs that should not be cached, can contain wildcards like '/admin*'
config(['litespeedcache.defaults.excludedUris' => [$csrfTokenUri . '*', $csrfFieldUri . '*']]);

// Array of query strings that should not be cached, can contain wildcards like '*utm_source=*'
config(['litespeedcache.defaults.excludedQueryStrings' => []]);

// Array of routes for this package
config(['litespeedcache.routes' => ['token' => $csrfTokenUri, 'field' => $csrfFieldUri] ]);
```

### Facade

[](#facade)

The package registers `\Joostvanveen\Litespeedcache\Cache` as a facade and sets default config values for `litespeedcache.defaults.enabled`, `litespeedcache.defaults.type`, `litespeedcache.defaults.lifetime`, `litespeedcache.defaults.excludedUris`, and `litespeedcache.defaults.excludedQueryStrings`.

```
use LitespeedCache;

[...]

// Cache use all default settings from config.
LitespeedCache::cache();

// Purge the cache
LitespeedCache::purge();
```

You can use all methods from `\Joostvanveen\Litespeedcache\Cache`, see  for full documentation.

Some examples:

```
// Full options example
// You can also set $excludedUris and $excludedQueryStrings in config.
$excludedUris = [
    'checkout*',
    'admin*',
];
$excludedQueryStrings = [
    '*direction=*',
];
LitespeedCache::setType('private')->setLifetime(120)
                                  ->addTags(['articles', 'en_GB'])
                                  ->addVary('value=mysubdomain')
                                  ->setExcludedUrls($excludedUris)
                                  ->setExcludedQueryStrings($excludedQueryStrings)
                                  ->cache();

// Purge cache using tags.
LitespeedCache::addTags('articles')->purge();

// If the lifetime is set to 0 the page will not be cached
(new Cache)->setEnabled(true)->setLifetime(0)->cache();
```

### Middleware

[](#middleware)

By default, the package contains a middleware that caches all pages (except cli).

You can find this middleware at `src/Middlewares/Cache.php`.

If you want to use your own middleware, you can disable the default middleware by setting the config value `litespeedcache.defaults.use_middleware` to `false`

1. Publish the config settings to your Laravel project.

```
php artisan vendor:publish --provider="Joostvanveen\LaravelLitespeedcache\LitespeedCacheServiceProvider" --tag=config
```

2. Set `use_middleware` to `false`

```
