Combined CSS Assets not found with CACHE_DRIVER "array"

Hi,

I just work on optimizing the caching of the website with Redis since I need tagged cache on several spots.

A second developer needed a quick workaround without the installation of Redis so I thought “array” as CACHE_DRIVER would be a good alternative.

However, it turned out that with array, some combined assets show an error message and the CSS is gone obviously. So I tested this on two platforms (one ubuntu, one windows) with CACHE_DRIVER “file” (removing the tagged cache code for a moment), “array” and “redis”.

While the combine files worked fine with “file” and “redis” on both platforms, “array” showed the same problem on both platforms.

What is the problem here?

Since this only happens on caching driver “array” I’m not sure if this might be a bug from october. Any help is welcome here. ^^

I also tried this approach adding the .css to the href of the linked css, but it didnt work:


.env:
CACHE_DRIVER=array

config/cache.php:

        'array' => [
            'driver' => 'array',
            'serialize' => false,
        ],

config/cms.php => still the default one

CSS Partial from the Layout:

    {# Styles #}
    <link href="{{ ['assets/css/theme.scss']|theme }}" rel="stylesheet" />

    {% if this.page.is_logged_in %}
    <link href="{{ ['assets/css/user.scss']|theme }}" rel="stylesheet" />
    {% endif %}

    {% if this.page.hide_ads %}
    <link href="{{ ['assets/css/premium.scss']|theme }}" rel="stylesheet" />
    {% else %}
    <link href="{{ ['assets/css/layout.scss']|theme }}" rel="stylesheet" />
    {% endif %}

    {% styles %}

    {# Bootstrap #}
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/css/bootstrap.min.css" rel="stylesheet"
        integrity="sha384-GLhlTQ8iRABdZLl6O3oVMWSktQOp6b7In1Zl3/Jr59b6EGGoI1aFkw7cmDA6j6gD" crossorigin="anonymous" />

HTML Output:

<link href="[myurl]/combine/6325f3647ca682b1416b1141509e2aa0-1684519928" rel="stylesheet" />
<link href="[myurl]/combine/c9914be9448a97e3f7dc2683bc6cb748-1681711805" rel="stylesheet" />
 <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-GLhlTQ8iRABdZLl6O3oVMWSktQOp6b7In1Zl3/Jr59b6EGGoI1aFkw7cmDA6j6gD" crossorigin="anonymous" />

Combiner File:

ApplicationException: The combiner file 'c9914be9448a97e3f7dc2683bc6cb748' is not found. in [webfolder]\modules\system\classes\CombineAssets.php:217
Stack trace:
#0 [webfolder]\modules\system\classes\SystemController.php(38): System\Classes\CombineAssets->getContents('c9914be9448a97e...')
#1 [webfolder]\vendor\laravel\framework\src\Illuminate\Routing\Controller.php(54): System\Classes\SystemController->combine('c9914be9448a97e...')
#2 [webfolder]\vendor\laravel\framework\src\Illuminate\Routing\ControllerDispatcher.php(43): Illuminate\Routing\Controller->callAction('combine', Array)
#3 [webfolder]\vendor\laravel\framework\src\Illuminate\Routing\Route.php(260): Illuminate\Routing\ControllerDispatcher->dispatch(Object(Illuminate\Routing\Route), Object(System\Classes\SystemController), 'combine')
#4 [webfolder]\vendor\laravel\framework\src\Illuminate\Routing\Route.php(205): Illuminate\Routing\Route->runController()
#5 [webfolder]\vendor\laravel\framework\src\Illuminate\Routing\Router.php(798): Illuminate\Routing\Route->run()
#6 [webfolder]\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php(141): Illuminate\Routing\Router->Illuminate\Routing\{closure}(Object(Illuminate\Http\Request))
#7 [webfolder]\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php(116): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#8 [webfolder]\vendor\laravel\framework\src\Illuminate\Routing\Router.php(799): Illuminate\Pipeline\Pipeline->then(Object(Closure))
#9 [webfolder]\vendor\laravel\framework\src\Illuminate\Routing\Router.php(776): Illuminate\Routing\Router->runRouteWithinStack(Object(Illuminate\Routing\Route), Object(Illuminate\Http\Request))
#10 [webfolder]\vendor\laravel\framework\src\Illuminate\Routing\Router.php(740): Illuminate\Routing\Router->runRoute(Object(Illuminate\Http\Request), Object(Illuminate\Routing\Route))
#11 [webfolder]\vendor\october\rain\src\Router\CoreRouter.php(32): Illuminate\Routing\Router->dispatchToRoute(Object(Illuminate\Http\Request))
#12 [webfolder]\vendor\laravel\framework\src\Illuminate\Foundation\Http\Kernel.php(190): October\Rain\Router\CoreRouter->dispatch(Object(Illuminate\Http\Request))
#13 [webfolder]\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php(141): Illuminate\Foundation\Http\Kernel->Illuminate\Foundation\Http\{closure}(Object(Illuminate\Http\Request))
#14 [webfolder]\vendor\barryvdh\laravel-debugbar\src\Middleware\InjectDebugbar.php(66): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#15 [webfolder]\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php(180): Barryvdh\Debugbar\Middleware\InjectDebugbar->handle(Object(Illuminate\Http\Request), Object(Closure))
#16 [webfolder]\vendor\laravel\framework\src\Illuminate\Foundation\Http\Middleware\PreventRequestsDuringMaintenance.php(86): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#17 [webfolder]\vendor\october\rain\src\Foundation\Http\Middleware\CheckForMaintenanceMode.php(23): Illuminate\Foundation\Http\Middleware\PreventRequestsDuringMaintenance->handle(Object(Illuminate\Http\Request), Object(Closure))
#18 [webfolder]\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php(180): October\Rain\Foundation\Http\Middleware\CheckForMaintenanceMode->handle(Object(Illuminate\Http\Request), Object(Closure))
#19 [webfolder]\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php(116): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#20 [webfolder]\vendor\laravel\framework\src\Illuminate\Foundation\Http\Kernel.php(165): Illuminate\Pipeline\Pipeline->then(Object(Closure))
#21 [webfolder]\vendor\laravel\framework\src\Illuminate\Foundation\Http\Kernel.php(134): Illuminate\Foundation\Http\Kernel->sendRequestThroughRouter(Object(Illuminate\Http\Request))
#22 [webfolder]\index.php(43): Illuminate\Foundation\Http\Kernel->handle(Object(Illuminate\Http\Request))
#23 {main}
...

I THOUGHT found a solution for this one, but I didnt:

The problem with the solution below: My scss files which were converted with the combiner, too. It would work with regular .css files, but not with .scss. So… problem remains open.

Maybe the post from below is still helping someone…

my problems remains open >.<


ORIGINAL POST:
The arrays within those links here trigger the combiner:
<link href="{{ ['assets/css/theme.scss']|theme }}" rel="stylesheet" />

However, since there’s only one file in each array and the other files are within some if/else conditions, the combiner is useless here anyways. So the easiest way is to remove the arrays:
<link href="{{ 'assets/css/theme.scss'|theme }}" rel="stylesheet" />

This way, the css files wont be combined and therefor no problem with the array caching exists.

In case there are multiple files to combine, I found a solution in an old git task:

=> Add an .env Variable: APP_ENV=dev

and depending on the environment, combine the css stuff … or not (or js in this example):

{% if this.environment == 'dev' %}
    <script src="{{ 'assets/vendor/jquery.min.js'|theme }}"></script>
    <script src="{{ 'assets/semantic/dist/semantic.min.js'|theme }}"></script>
    <script src="{{ 'assets/javascript/app.js' | theme }}"></script>
    {% framework extras %}
{% else %}
    <script src="{{ [
     'assets/vendor/jquery.js',
     'assets/semantic/dist/semantic.js',
     'assets/javascript/app.js',
     '@framework',
     '@framework.extras'
     ]|theme }}"></script>
{% endif %}

Setting the cache to array is used by unit testing. It is not anticipated to use it in production since it would delete the cache for every PHP request, which defeats the purpose.

It is best to find a way to not use the array driver for cache.

1 Like

Well, it’s not prod, it’s dev, but I’ll still setup redis for it.

Thanks ^^

If it’s dev, why not use the filesystem driver?

cause I use tagged cache…

Oh, I see… I did not know the file driver does not support tags. You could ask the Laravel community about it.