GithubHelp home page GithubHelp logo

lscache-drupal's Introduction

LiteSpeed Cache for Drupal 8+

  • Fastest Page cache for Drupal CMS.
  • Page Cache for both Logged In and Logged Out users.
  • Auto Purge relate Page Caches when content changes.
  • Drush and non-Drush cli commands for Cache warmup/clear.
  • Web GUI warmup will also warm up Private Cache for Logged In Users if enabled.
  • Supports latest releases of Drupal 8+, 9+ and 10+ .

See the LiteSpeed Website for more information about LiteSpeed Cache for Drupal.

See the full documentation for more installation and configuration help.

Prerequisites

This version of LiteSpeed Cache requires Drupal 8 or later and LiteSpeed Web Server (LSWS) 5.2.3 or later.

Download

Download the LiteSpeed Cache Module to your local computer from:

https://github.com/litespeedtech/lscache-drupal/archive/master.zip
Click to show details

Plugin Installation picture

If you use Composer to manage dependencies, require the module in your project composer.json:

  "repositories": [
    {
      "type": "vcs",
      "url": "[email protected]:litespeedtech/lscache-drupal.git"
    }
  ],
  "require": {
    "litespeedtech/lscache-drupal": "dev-master"
  },

Install Plugin

Once you have downloaded the plugin, you can install by visiting:

http://example.com/admin/modules/install

Using the browse button, you can upload the plugin you just downloaded and start the installation. Once installed, enable the plugin by going to:

http://example.com/drupal/admin/modules
Click to show details

Plugin Installation picture

  • Use the search box to search for a module.
  • Check the checkbox next to LiteSpeed Cache.
  • Click Install.
  • Turn on LiteSpeed Cache in Module Settings.

Configuration

This step is optional. Once the plugin is activated, your cache is already up and running, but on the configuration screen, you can customize few settings.

Go to

http://example.com/admin/config/development/lscache

LiteSpeed Cache Drupal Plugin Configuration

  • Warmup this site: Warm up the LSCache of the current Drupal site. It will also warm up Private Cache for Logged In Users if enabled.
  • Clear this site: Clears the LSCache of the current Drupal site. It will not clear the LSCache of other sites if you have multiple CMS sites running on the same virtual host.
  • Public Cache TTL: Amount of time LiteSpeed Web Server will save pages in the public cache.
  • Private Cache TTL: Amount of time LiteSpeed web server will save ESI Block Contents in the Private cache. OpenLiteSpeed does not support Private Cache.
  • ESI Blocks Setting: The list of ESI blocks on general logged in pages. The ESI Block name should be the same as the div id inside the HTML source. For example, in the following div block, the ESI Block name would be bar-administrator:
     <div id="bar-administrator">...<div>
    
  • Debug: If turned on, LiteSpeed Cache will print the LSCache header to LSWS log files.

CLI commands

CLI commands are only allowed to execute from the website host server.

Purge All Cache

curl -N "http://example.com/lscpurgeall"

or in /drupal_root/vendor/bin folder, execute drush command:

./drush lscache:purgeall example.com

WarmUp whole website

curl -N "http://example.com/lscwarmup"

or in /drupal_root/vendor/bin folder, execute drush command:

./drush lscache:warmup example.com

CLI warmup command can only warm up public page caches. If you want to warm up Private Cache for Logged In Users, you need to use the Web GUI warmup in the LSCache admin panel.

lscache-drupal's People

Contributors

code-egg avatar jefflogan303 avatar litespeedtech avatar lslisa avatar saschaeggi avatar usmannasir avatar wadedang avatar woet avatar wuhuachen avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

lscache-drupal's Issues

Feature Request: Vary cache based on Drupal user roles

Often different Drupal roles require different page contents. For instance, anonymous may require different content than authenticated and admin will require different content than both anonymous and authenticated. It is typical that admin should not be cached, but quite often pages for authenticated user roles are all the same for the role and so can be cached.

LSCache does not differentiate between authenticated and admin roles. When users authenticate, LSCache sets _lscache_vary to 'loggedin' no matter the user role, thus, unless private cache is set, pages are not cached for authenticated users. But for large sites with thousands or tens of thousands of users, private cache is untenable. Caching per user role will increase the number of cached pages, especially when there are multiple roles below the admin level, but will be more efficient than using private cache.

Preferably, LSCache Drupal module would support the feature of varying cache based on defined user roles, as by the site administrator.

Currently, this feature is supported with Varnish + Advanced Varnish Drupal module. For reference, the Advanced Varnish module allows site administrators to turn on cache for authenticated users. For example, when the user role 'authenticated' is allowed to cache, the Advanced Varnish Cache module sets two cookies: ADVINF and ADVBIN. The former specifies the roles the authenticated user possesses, while the latter specifies the appropriate cache bin for the user. The ADVBIN value varies depending on the user role such that all roles that should be cached have a unique bin value, i.e., if ADVINF=authenticated, ADVBIN=1234, but if ADVINF=authenticated_other, ADVBIN=5678. Thus the vary header says to look for the bin info in the cookie and serve the corresponding cached page for the role. When a role should not have pages cached for it, no ADVINF or ADVBIN cookies are set. On logout, if the cookies are set the values are deleted.

https://www.drupal.org/docs/contributed-modules/advanced-varnish/cache-for-authenticated-users
https://www.drupal.org/project/adv_varnish

Undefined constant MAIN_REQUEST

After upgrading Litespeed from 1.2 to 1.3, I am getting WSOD. Upon checking the logs, I see this:

php Error: Undefined constant Drupal\lite_speed_cache\StackMiddleware\LiteSpeedCache::MAIN_REQUEST in
                                            Drupal\lite_speed_cache\StackMiddleware\LiteSpeedCache->handle() (line 109 of...

I can see from this latest commit that MAIN_REQUEST is being used instead of MASTER_REQUEST.

MASTER_REQUEST is required for HttpKernelInterface:

interface HttpKernelInterface
{
    public const MASTER_REQUEST = 1;
    public const SUB_REQUEST = 2;

    /**
     * Handles a Request to convert it to a Response.
     *
     * When $catch is true, the implementation must catch all exceptions
     * and do its best to convert them to a Response instance.
     *
     * @param int  $type  The type of the request
     *                    (one of HttpKernelInterface::MASTER_REQUEST or HttpKernelInterface::SUB_REQUEST)
     * @param bool $catch Whether to catch exceptions or not
     *
     * @return Response A Response instance
     *
     * @throws \Exception When an Exception occurs during processing
     */
    public function handle(Request $request, $type = self::MASTER_REQUEST, $catch = true);
}

Would be great if this can be fixed asap as I cannot use Litespeed anymore. I'll need to revert to 1.2 for now.

Drupal messages

If status, warning, or error messages are added, they do not get displayed as the page loads from cache. For example, adding a new node as an anonymous user results in a message being displayed on the home page. This does not show up.

Drupal 9 compability

Please fix the following to be compatible with Drupal 9:
modules/contrib/lscache/src/Form/LSCacheForm.php | 167 | Call to deprecated function drupal_set_message(). Deprecated in drupal:8.5.0 and is removed from drupal:9.0.0. Use Drupal\Core\Messenger\MessengerInterface::addMessage() instead.

modules/contrib/lscache/src/Form/LSCacheForm.php | 175 | Call to deprecated function drupal_set_message(). Deprecated in drupal:8.5.0 and is removed from drupal:9.0.0. Use Drupal\Core\Messenger\MessengerInterface::addMessage() instead.

Upgrade problem

I upgraded my v1.0 lscache Drupal module to v1.2 by putting the site in maintenance mode, then copying the files over. After doing this, my site was broken. I recovered by replacing the module files, then found this in the Drupal log:

Error: Class 'Drupal\lite_speed_cache\StackMiddleware\LiteSpeedCache' not found in Drupal\Component\DependencyInjection\Container->createService() (line 262 of /home/nature50/public_html/core/lib/Drupal/Component/DependencyInjection/Container.php)
#0 /home/nature50/public_html/core/lib/Drupal/Component/DependencyInjection/Container.php(176): Drupal\Component\DependencyInjection\Container->createService(Array, 'http_middleware...')
#1 /home/nature50/public_html/core/lib/Drupal/Component/DependencyInjection/Container.php(437): Drupal\Component\DependencyInjection\Container->get('http_middleware...', 1)
#2 /home/nature50/public_html/core/lib/Drupal/Component/DependencyInjection/Container.php(240): Drupal\Component\DependencyInjection\Container->resolveServicesAndParameters(Array)
#3 /home/nature50/public_html/core/lib/Drupal/Component/DependencyInjection/Container.php(176): Drupal\Component\DependencyInjection\Container->createService(Array, 'http_middleware...')
#4 /home/nature50/public_html/core/lib/Drupal/Component/DependencyInjection/Container.php(437): Drupal\Component\DependencyInjection\Container->get('http_middleware...', 1)
#5 /home/nature50/public_html/core/lib/Drupal/Component/DependencyInjection/Container.php(240): Drupal\Component\DependencyInjection\Container->resolveServicesAndParameters(Array)
#6 /home/nature50/public_html/core/lib/Drupal/Component/DependencyInjection/Container.php(176): Drupal\Component\DependencyInjection\Container->createService(Array, 'http_middleware...')
#7 /home/nature50/public_html/core/lib/Drupal/Component/DependencyInjection/Container.php(437): Drupal\Component\DependencyInjection\Container->get('http_middleware...', 1)
#8 /home/nature50/public_html/core/lib/Drupal/Component/DependencyInjection/Container.php(240): Drupal\Component\DependencyInjection\Container->resolveServicesAndParameters(Array)
#9 /home/nature50/public_html/core/lib/Drupal/Component/DependencyInjection/Container.php(176): Drupal\Component\DependencyInjection\Container->createService(Array, 'http_middleware...')
#10 /home/nature50/public_html/core/lib/Drupal/Component/DependencyInjection/Container.php(437): Drupal\Component\DependencyInjection\Container->get('http_middleware...', 1)
#11 /home/nature50/public_html/core/lib/Drupal/Component/DependencyInjection/Container.php(240): Drupal\Component\DependencyInjection\Container->resolveServicesAndParameters(Array)
#12 /home/nature50/public_html/core/lib/Drupal/Component/DependencyInjection/Container.php(176): Drupal\Component\DependencyInjection\Container->createService(Array, 'http_kernel')
#13 /home/nature50/public_html/core/lib/Drupal/Core/DrupalKernel.php(1370): Drupal\Component\DependencyInjection\Container->get('http_kernel')
#14 /home/nature50/public_html/core/lib/Drupal/Core/DrupalKernel.php(717): Drupal\Core\DrupalKernel->getHttpKernel()
#15 /home/nature50/public_html/index.php(19): Drupal\Core\DrupalKernel->handle(Object(Symfony\Component\HttpFoundation\Request))
#16 {main}

I managed to do the upgrade by uninstalling the old module, replacing it, then re-installing it.

After upgrading to D10, css/js are broken on some pages

I upgraded a site from D9 to D10.

This site was using Litespeed Drupal module (v 1.2) on D9.

On D10, I used v1.5.

End result: some pages worked and some did not.

I disabled all caching and css/js aggregation. Problem still persists.

For the pages that did work, the correct css/js files are accessed.

For the pages that didn't work, Drupal is trying to get the optimized css/js files but they do not exist (this is with css/jss disabled).

When I checked the Drupal logs I see:

Symfony\Component\HttpKernel\Exception\BadRequestHttpException: The theme must be passed as a query argument in Drupal\system\Controller\AssetControllerBase->deliver() (line 132 of /code/web/core/modules/system/src/Controller/AssetControllerBase.php).

When I uninstall the LiteSpeed Drupal module, everything works perfectly.

I don't know if this issue is related, but here it is anyway: https://www.drupal.org/project/drupal/issues/3393274

I have resorted to not using the Drupal Litespeed module until this is fixed.

Let me know if you need any additional info. I have the db backup on D10 with Litespeed enabled.

Just to note, I am not 100% sure if this is the fault of the Litespeed module or just my hosting. My hosting is using Litespeed webserver and was working perfectly using D9 and Litespeed v1.3.

It's difficult to test this locally. Locally, I am using ddev with nginx so I cannot replicate the problem locally.

You are referring to page cache and not dynamic page cache.

In Drupal there are two types of caches.

Page cache that works for anonymous users.
Dynamic page cache - that caches parts of the page and generates only the non-cache-able parts from it.

From what I see in the code and descriptions in this module, you are making alternative variant for the page cache, but stating dynamic page cache everywhere.

You need to extend also documentation on what users installing this module should do with the core's dynamic page and standard page cache modules. Having both running at the same time is likely not needed.

Proper benchmarks comparing D8 core with and without the plugin will be appreciated.

Breaks first Commerce "Add to cart" for anonymous users

For some reason clicking "Add to cart" for a Commerce product the first time does not result in a new session cookie being saved. Although the product is added, there is no visible sign of this, confusing the customer.

I think the Product page is being cached for the "no cookie" state, and not refreshed when Commerce sets a cookie for the cart.

Turning off lscache in the Drupal admin settings fixes the problem.

Upgrade for Drupal 10

I may well do the work for this, but do not yet have time.

The two issues picked up by PHPstan are:

File: web/modules/contrib/lite_speed_cache/src/EventSubscriber/LiteSpeedCacheSubscriber.php
Line: 128
Comment: Parameter $event of method Drupal\lite_speed_cache\EventSubscriber\LiteSpeedCacheSubscriber::onRouteMatch() has typehint with deprecated class Symfony\Component\HttpKernel\Event\GetResponseEvent: since Symfony 4.3, use RequestEvent instead

File: web/modules/contrib/lite_speed_cache/src/EventSubscriber/LiteSpeedCacheSubscriber.php
Line: 166
Comment: Parameter $event of method Drupal\lite_speed_cache\EventSubscriber\LiteSpeedCacheSubscriber::onResponse() has typehint with deprecated class Symfony\Component\HttpKernel\Event\FilterResponseEvent: since Symfony 4.3, use ResponseEvent instead

and the .info.yml file needs to have "^9 || ^10" as the version requirement.

Drupal 8.8.0 : TypeError: Argument 2 passed to Drupal\page_cache\StackMiddleware\PageCache::storeResponse()

When I try to log in I get the following message:
The website encountered an unexpected error. Please try again later.
TypeError: Argument 2 passed to Drupal\page_cache\StackMiddleware\PageCache::storeResponse() must be an instance of Symfony\Component\HttpFoundation\Response, null given, called in /home/naukispo/domains/nauki-spoleczne.info/public_html/core/modules/page_cache/src/StackMiddleware/PageCache.php on line 195 in Drupal\page_cache\StackMiddleware\PageCache->storeResponse() (line 212 of core/modules/page_cache/src/StackMiddleware/PageCache.php).

I use litespeed and memcached.

Works only on the homepage

I can see the headers X-LiteSpeed-Cache: hit or X-LiteSpeed-Cache: miss only in the homepage. I cannot see these headers in other pages of the site.

How to reproduce
I added this module to an existing site, enabled the module and enabled the Debug option.

Expected behavior
I would expect to see a hit or a miss on every page.

Things I've tried

  1. I have looked at the pages as an anonymous user.
  2. I've also tried using Chrome Incognito Mode.
  3. I have uninstalled the core Drupal Internal Page Cache module suspecting a conflict while leaving installed the Dynamic cache module.

Thank you for your work on this module.

Drupal 8.6.x issue: TypeError: Argument 2 passed to Drupal\page_cache\StackMiddleware\PageCache::storeResponse()

I get the following error for image generating (and other files too) since upgrading to Drupal 8.6.x (Currently on 8.6.7):

TypeError: Argument 2 passed to Drupal\page_cache\StackMiddleware\PageCache::storeResponse() must be an instance of Symfony\Component\HttpFoundation\Response, null given, called in /home/saschaeg/public_html/saschaeggenberger.com/core/modules/page_cache/src/StackMiddleware/PageCache.php on line 188 in Drupal\page_cache\StackMiddleware\PageCache->storeResponse() (line 205 of /home/saschaeg/public_html/saschaeggenberger.com/core/modules/page_cache/src/StackMiddleware/PageCache.php) #0 /home/saschaeg/public_html/saschaeggenberger.com/core/modules/page_cache/src/StackMiddleware/PageCache.php(188): Drupal\page_cache\StackMiddleware\PageCache->storeResponse(Object(Symfony\Component\HttpFoundation\Request), NULL) #1 /home/saschaeg/public_html/saschaeggenberger.com/core/modules/page_cache/src/StackMiddleware/PageCache.php(121): Drupal\page_cache\StackMiddleware\PageCache->fetch(Object(Symfony\Component\HttpFoundation\Request), 1, true) #2 /home/saschaeg/public_html/saschaeggenberger.com/core/modules/page_cache/src/StackMiddleware/PageCache.php(75): Drupal\page_cache\StackMiddleware\PageCache->lookup(Object(Symfony\Component\HttpFoundation\Request), 1, true) #3 /home/saschaeg/public_html/saschaeggenberger.com/core/lib/Drupal/Core/StackMiddleware/ReverseProxyMiddleware.php(47): Drupal\page_cache\StackMiddleware\PageCache->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true) #4 /home/saschaeg/public_html/saschaeggenberger.com/core/lib/Drupal/Core/StackMiddleware/NegotiationMiddleware.php(52): Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true) #5 /home/saschaeg/public_html/saschaeggenberger.com/vendor/stack/builder/src/Stack/StackedHttpKernel.php(23): Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true) #6 /home/saschaeg/public_html/saschaeggenberger.com/core/lib/Drupal/Core/DrupalKernel.php(693): Stack\StackedHttpKernel->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true) #7 /home/saschaeg/public_html/saschaeggenberger.com/index.php(19): Drupal\Core\DrupalKernel->handle(Object(Symfony\Component\HttpFoundation\Request)) #8 {main}.

These must be a change of passed arguments from 8.5.x to 8.6.x

Tags based invalidation not working because LSCacheTagsInvalidator::$tags gets overwritten

Editing content does not purge LSCache tags automatically at the moment because wrong tags are sent in the X-LiteSpeed-Purge HTTP response header.

If we are editing node 48 in Drupal for example, the correct cache purge tag list would be something like4xx-response,node:48,node_list but for example tags 4xx-response,menu_link_content:33,menu_link_content_list are actually set in the header.

Because of this, only way to purge cache successfully is manual Clear this site or Clear all operation from the LSCache module settings.

Debug logging the LSCacheTagsInvalidator -> invalidateTags function reveals that correct tags are first populated to LSCacheTagsInvalidator::$tags but it gets overwritten with subsequents calls that produce route_match, menu_link_content and menu_link_content_list tags which are incorrect for purging the cache. The last iteration is what gets actually sent in the X-LiteSpeed-Purge header.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.