Skip to content

Commit

Permalink
Merge pull request #108 from JarvusInnovations/fixes/create-exemption…
Browse files Browse the repository at this point in the history
…s-cache

fix(exemptions): create cache directory automatically
  • Loading branch information
themightychris authored Feb 2, 2021
2 parents c969d63 + 6fea57f commit b665dd9
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions php-classes/Gatekeeper/Utils/IPPattern.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,8 @@ public static function parse($pattern)
}

// try to load from filesystem cache
$cacheFilePath = join('/', [
Storage::getLocalStorageRoot(),
static::$fsRootDir,
$patternHash . '.php'
]);
$cacheDirPath = Storage::getLocalStorageRoot() . '/' . static::$fsRootDir;
$cacheFilePath = "{$cacheDirPath}/{$patternHash}.php";

try {
$closure = include($cacheFilePath);
Expand Down Expand Up @@ -80,7 +77,6 @@ public static function parse($pattern)

// fast path for static IP lists
if (count($subPatternsByType['cidr']) === 0 && count($subPatternsByType['wildcard']) === 0) {
// TODO: cache to a file?
return $cache[$patternHash] = $subPatternsByType['ip'];
}

Expand All @@ -107,6 +103,10 @@ public static function parse($pattern)
$closureFunctionString .= "};\n";

// write to filesystem
if (!is_dir($cacheDirPath)) {
mkdir($cacheDirPath, 0777, true);
}

file_put_contents($cacheFilePath, $closureFunctionString);

return $cache[$patternHash] = include($cacheFilePath);
Expand Down

0 comments on commit b665dd9

Please sign in to comment.