Skip to content

Commit

Permalink
[1.x] Flushes Str cache between requests (#468)
Browse files Browse the repository at this point in the history
* Flushes `Str` cache between requests

* Bumps framework version
  • Loading branch information
nunomaduro authored Jan 25, 2022
1 parent 1e06328 commit 3c4e717
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 1 deletion.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
],
"require": {
"php": "^8.0",
"laravel/framework": "^8.77|^9.0",
"laravel/framework": "^8.81|^9.0",
"laminas/laminas-diactoros": "^2.5",
"laravel/serializable-closure": "^1.0",
"symfony/psr-http-message-bridge": "^2.0"
Expand Down
1 change: 1 addition & 0 deletions src/Concerns/ProvidesDefaultConfigurationOptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ public static function prepareApplicationForNextOperation(): array
\Laravel\Octane\Listeners\FlushLogContext::class,
\Laravel\Octane\Listeners\FlushArrayCache::class,
\Laravel\Octane\Listeners\FlushMonologState::class,
\Laravel\Octane\Listeners\FlushStrCache::class,
\Laravel\Octane\Listeners\FlushTranslatorCache::class,

// First-Party Packages...
Expand Down
19 changes: 19 additions & 0 deletions src/Listeners/FlushStrCache.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

namespace Laravel\Octane\Listeners;

use Illuminate\Support\Str;

class FlushStrCache
{
/**
* Handle the event.
*
* @param mixed $event
* @return void
*/
public function handle($event)
{
Str::flushCache();
}
}
39 changes: 39 additions & 0 deletions tests/Listeners/FlushStrCacheTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

namespace Laravel\Octane\Listeners;

use Illuminate\Http\Request;
use Illuminate\Support\Str;
use Laravel\Octane\Tests\TestCase;
use ReflectionClass;

class FlushStrCacheTest extends TestCase
{
public function test_str_is_flushed()
{
Str::flushCache();

[$app, $worker, $client] = $this->createOctaneContext([
Request::create('/test-str-cache', 'GET'),
Request::create('/', 'GET'),
]);

$app['router']->middleware('web')->get('/', function () {
return 'Hello World';
});

$app['router']->middleware('web')->get('/test-str-cache', function () {
return Str::snake('Taylor Otwell');
});

$reflection = new ReflectionClass(Str::class);
$property = $reflection->getProperty('snakeCache');
$property->setAccessible(true);

$this->assertEmpty($property->getValue());

$worker->run();

$this->assertEmpty($property->getValue());
}
}

0 comments on commit 3c4e717

Please sign in to comment.