Download the PHP package litespeed/lscache-laravel without Composer

On this page you can find all versions of the php package litespeed/lscache-laravel. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package lscache-laravel

Laravel LSCache

This package allows you to use lscache together with Laravel.

It provides two middlewares and one facade:

Installation

Require this package using composer.

Laravel uses Auto-Discovery, so you won't have to make any changes to your application, the two middlewares and facade will be available right from the beginning.

Steps for Laravel >=5.1 and <=5.4

The package can be used for Laravel 5.1 to 5.4 as well, however due to lack of Auto-Discovery, a few additional steps have to be performed.

In config/app.php you have to add the following code in your aliases:

In app/Http/Kernel.php you have to add the two middlewares under middleware and routeMiddleware:

Copy lscache.php to config/:

Copy the package config/lscache.php file to your config/ directory.

important: Do not add the ServiceProvider under providers in config/app.php.

Steps for Laravel 5.5 and above

You should publish the package configuration, which allows you to set the defaults for the X-LiteSpeed-Cache-Control header:

Enable CacheLookup for LiteSpeed Cache

To enable CacheLookup for LiteSpeed Cache, you have to include the following code, either on server, vhost or .htaccess level:

Usage

The package comes with 3 functionalities: Setting the cache control headers for lscache, settings specific tags and purging.

cache-control

You'll be able to configure defaults in the config/lscache.php file, here you can set the max-age (default_ttl), the cacheability (default_cacheability) such as public, private or no-cache or enable esi (esi) in the X-LiteSpeed-Cache-Control response header.

If the default_ttl is set to 0, then we won't return the X-LiteSpeed-Cache-Control response header.

You can control the config settings in your .env file as such:

You set the cache-control header for lscache using a middleware, so we can in our routes do something like this:

Below is 4 examples:

Now, you'll also be able to apply the same middleware to route groups in Laravel, let's take an example:

In the above case, we've set the whole admin group to be private with esi enabled and a max-age of 120 seconds, however in the /admin/stats route, we override the X-LiteSpeed-Cache-Control header to no-cache.

tags

You're also able to set tags for LSCache using the lstags middleware. If we use the previous example of our admin route group:

Here we've added the lstags:admin middleware, this means that the cache will get tagged with an admin tag, so when we later want to purge the cache, we can target all admin pages using the tag admin.

You can also do more complex tags as such:

purge

If we have an admin interface that controls for example a blog, when you publish a new article, you might want to purge the frontpage of the blog so the article appears in the overview.

You'd do this in your controller by doing

In the above example, we're simply telling it to add an additional header called X-LiteSpeed-Purge with the value stale,/, this will invalidate the frontpage of the site.

You can also purge everything by doing:

One or multiple URIs can be purged by using a comma-separated list:

You can purge individual or multiple tags:

Or if you want to purge private cache by tag:

You even have the possibility to purge a set of public tags and and purge all the private tags:

LiteSpeed Cache for Laravel 1.1.0 comes with a stale option turned on by default for the LSCache::purge function, this can be turned off by using false as the second parameter in the purge function:

Why stale purge matters

By default the way Lscache works in LiteSpeed is by purging an element in the cache, and next request will generate the cached version.

This works great if you're running a fairly low traffic site, however if your application takes let's say 2 seconds to process a given request, all traffic received to this endpoint within those 2 seconds will end up hitting the backend, and all visitors will hit PHP.

By using the stale, keyword in front the "key" you're purging, you're telling Lscache to purge the item, but if multiple visitors hit the same endpoint right after each other, only the first visitor will be the one generating the cache item, all remaining vistors will get served the stale cached page until the new cached page is available.

Since a page generation should be rather fast, we're only serving this stale content for maybe a couple of seconds, thus also the reason it's being enabled by default.

If your application cannot work with stale content at all, then you can use false or $stale=false as the second parameter in the LSCache::purge() function to disable this functionality.

You can also purge specific public tags by adding ~s after the tag, such as:

Only pubtag2 will be served stale.

Laravel Authentication

If you use authentication in Laravel for handling guests and logged-in users, you'll likely want to also separate the cache for people based on this.

This can be done in the .htaccess file simply by using the cache-vary on the Authorization cookie:

Note: In the above example we use Authorization, this may have a different name depending on your setup, so it has to be changed accordingly.


All versions of lscache-laravel with dependencies

PHP Build Version
Package Version
Requires illuminate/support Version ^5.1|^6|^7|^8|^9|^10.0|^11.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package litespeed/lscache-laravel contains the following files

Loading the files please wait ....