Skip to content

Commit

Permalink
Simplify file store to only have custom paths for stache ...
Browse files Browse the repository at this point in the history
Closes #2294
Closes #952
  • Loading branch information
jasonvarga committed Aug 25, 2020
1 parent 75764b2 commit 0cb6dfc
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 27 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
- The `FormSubmitted` event gets a `submission` property. [#2271](https://github.com/statamic/cms/issues/2271)
- Images are inline in Replicator previews. [#2267](https://github.com/statamic/cms/issues/2267)
- Addon thumbnail alignment. [#2272](https://github.com/statamic/cms/issues/2272)
- Simplify how our custom cache store creates paths. Fixes a Windows pathing issue. [#952](https://github.com/statamic/cms/issues/952)
- Translations. [#2282](https://github.com/statamic/cms/issues/2282) [#2256](https://github.com/statamic/cms/issues/2256)


Expand Down
31 changes: 4 additions & 27 deletions src/Extensions/FileStore.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,40 +4,17 @@

use Illuminate\Cache\FileStore as LaravelFileStore;
use Illuminate\Contracts\Cache\Store;
use Statamic\Support\Str;

class FileStore extends LaravelFileStore implements Store
{
/**
* Get the full path for the given cache key.
*
* @param string $key
* @return string
*/
protected function path($key)
{
$namespaces = explode(':', $key);
array_pop($namespaces);

// Stache keys get put into their own folder for readability.
if (isset($namespaces[0]) && $namespaces[0] === 'stache') {
return $this->getStachePath($key);
if (! Str::startsWith($key, 'stache::')) {
return parent::path($key);
}

$parts = array_slice(str_split($hash = md5($key), 2), 0, 2);

return $this->directory.'/'.implode('/', $namespaces).'/'.implode('/', $parts).'/'.$hash;
}

/**
* Stache keys will get stored without being hashed.
*
* @param string $key
* @return string
*/
private function getStachePath($key)
{
// remove the "stache::" prefix
$key = substr($key, 8);
$key = Str::after($key, 'stache::');

return $this->directory.'/stache/'.str_replace('::', '/', $key);
}
Expand Down

0 comments on commit 0cb6dfc

Please sign in to comment.