Skip to content

Commit

Permalink
Merge pull request #407 from bearsunday/local_cache_module
Browse files Browse the repository at this point in the history
Install Psr6LocalCacheModule in production
  • Loading branch information
koriym committed Oct 15, 2022
2 parents 77ab2d1 + 384d564 commit fe0192f
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 7 deletions.
7 changes: 4 additions & 3 deletions composer.json
Expand Up @@ -27,7 +27,7 @@
"doctrine/cache": "^1.10 || ^2.0",
"doctrine/annotations": "^1.11",
"koriym/http-constants": "^1.1",
"ray/psr-cache-module": "^1.1.2",
"ray/psr-cache-module": "^1.3",
"symfony/cache": "^5.3",
"psr/cache": "^1.0",
"koriym/attributes": "^1.0",
Expand Down Expand Up @@ -84,11 +84,12 @@
"cs": ["./vendor/bin/phpcs"],
"cs-fix": ["./vendor/bin/phpcbf src tests"],
"clean": ["./vendor/bin/phpstan clear-result-cache", "./vendor/bin/psalm --clear-cache", "rm -rf tests/tmp/*.php"],
"sa": ["psalm --show-info=true", "./vendor/bin/phpstan analyse --no-ansi --no-progress -c phpstan.neon"],
"sa": ["psalm --show-info=true", "./vendor/bin/phpstan analyse --no-ansi --no-progress -c phpstan.neon --memory-limit=-1"],
"metrics": ["./vendor/bin/phpmetrics --report-html=build/metrics --exclude=Exception --junit=build/junit.xml src"],
"phpmd": ["./vendor/bin/phpmd --exclude src/Annotation src text ./phpmd.xml"],
"build": ["@cs", "@sa", "@pcov", "@metrics"],
"compile": "./bin/bear.compile FakeVendor\\\\HelloWorld prod-app ./tests/Fake/fake-app"
"compile": "./bin/bear.compile FakeVendor\\\\HelloWorld prod-app ./tests/Fake/fake-app",
"baseline": "phpstan analyse -configuration -c phpstan.neon --generate-baseline --memory-limit=-1 ;psalm --set-baseline=psalm-baseline.xml"
},
"config": {
"allow-plugins": {
Expand Down
26 changes: 26 additions & 0 deletions psalm-baseline.xml
@@ -0,0 +1,26 @@
<?xml version="1.0" encoding="UTF-8"?>
<files psalm-version="4.29.0@7ec5ffbd5f68ae03782d7fd33fff0c45a69f95b3">
<file src="src/Compiler.php">
<PossiblyUndefinedArrayOffset occurrences="1">
<code>$_SERVER['REQUEST_TIME_FLOAT']</code>
</PossiblyUndefinedArrayOffset>
<RedundantCondition occurrences="2">
<code>assert(is_float($start))</code>
<code>is_float($start)</code>
</RedundantCondition>
</file>
<file src="src/Compiler/CompileAutoload.php">
<PossiblyUndefinedArrayOffset occurrences="1">
<code>$_SERVER['REQUEST_TIME_FLOAT']</code>
</PossiblyUndefinedArrayOffset>
<RedundantCondition occurrences="2">
<code>assert(is_float($start))</code>
<code>is_float($start)</code>
</RedundantCondition>
</file>
<file src="src/Compiler/FakeRun.php">
<ArgumentTypeCoercion occurrences="1">
<code>$GLOBALS</code>
</ArgumentTypeCoercion>
</file>
</files>
1 change: 1 addition & 0 deletions psalm.xml
Expand Up @@ -6,6 +6,7 @@
xmlns="https://getpsalm.org/schema/config"
xsi:schemaLocation="https://getpsalm.org/schema/config vendor-bin/tools/vendor/vimeo/psalm/config.xsd
https://getpsalm.org/schema/config "
errorBaseline="psalm-baseline.xml"
>
<projectFiles>
<directory name="src"/>
Expand Down
4 changes: 2 additions & 2 deletions src/Context/ProdModule.php
Expand Up @@ -23,7 +23,7 @@
use Ray\Di\Scope;
use Ray\PsrCacheModule\Annotation\Local;
use Ray\PsrCacheModule\LocalCacheProvider;
use Ray\PsrCacheModule\Psr6ApcuModule;
use Ray\PsrCacheModule\Psr6LocalCacheModule;

/**
* @codeCoverageIgnore
Expand All @@ -45,7 +45,7 @@ protected function configure(): void
private function installCacheModule(): void
{
$this->install(new ProdQueryRepositoryModule());
$this->install(new Psr6ApcuModule());
$this->install(new Psr6LocalCacheModule());
/** @psalm-suppress DeprecatedClass */
$this->bind(CacheItemInterface::class)->annotatedWith(EtagPool::class)->toProvider(LocalCacheProvider::class);
$this->bind(Reader::class)->toConstructor(
Expand Down
3 changes: 1 addition & 2 deletions src/Injector.php
Expand Up @@ -9,7 +9,6 @@
use Ray\Di\AbstractModule;
use Ray\Di\InjectorInterface;
use Symfony\Component\Cache\Adapter\ApcuAdapter;
use Symfony\Component\Cache\Adapter\ChainAdapter;
use Symfony\Component\Cache\Adapter\FilesystemAdapter;
use Symfony\Contracts\Cache\CacheInterface;

Expand All @@ -31,7 +30,7 @@ public static function getInstance(string $appName, string $context, string $app
{
$meta = new Meta($appName, $context, $appDir);
$cacheNamespace = str_replace('/', '_', $appDir) . $context;
$cache ??= new ChainAdapter([new ApcuAdapter($cacheNamespace), new FilesystemAdapter('', 0, $meta->tmpDir . '/injector')]);
$cache ??= ApcuAdapter::isSupported() ? new ApcuAdapter($cacheNamespace) : new FilesystemAdapter('', 0, $meta->tmpDir . '/injector');

return PackageInjector::getInstance($meta, $context, $cache);
}
Expand Down

0 comments on commit fe0192f

Please sign in to comment.