77
88namespace Magento \RemoteStorage \Driver \Cache ;
99
10+ use League \Flysystem \Adapter \Local ;
1011use League \Flysystem \Cached \CacheInterface ;
1112use League \Flysystem \Cached \Storage \Memory ;
1213use League \Flysystem \Cached \Storage \Predis ;
14+ use League \Flysystem \Cached \Storage \Adapter ;
15+ use Magento \Framework \App \Filesystem \DirectoryList ;
16+ use Magento \Framework \Filesystem ;
1317use Magento \RemoteStorage \Driver \DriverException ;
18+ use Magento \RemoteStorage \Driver \DriverPool ;
1419use Predis \Client ;
1520
1621/**
@@ -20,14 +25,32 @@ class CacheFactory
2025{
2126 public const ADAPTER_PREDIS = 'predis ' ;
2227 public const ADAPTER_MEMORY = 'memory ' ;
28+ public const ADAPTER_LOCAL = 'local ' ;
2329
2430 private const CACHE_KEY = 'storage ' ;
31+ private const CACHE_FILE = 'storage_cache.json ' ;
2532
2633 /**
2734 * Cache for 30 days.
2835 */
2936 private const CACHE_EXPIRATION = 30 * 86400 ;
3037
38+ /**
39+ * @var string
40+ */
41+ private $ localCacheRoot ;
42+
43+ /**
44+ * @param Filesystem $filesystem
45+ */
46+ public function __construct (Filesystem $ filesystem )
47+ {
48+ $ this ->localCacheRoot = $ filesystem ->getDirectoryRead (
49+ DirectoryList::VAR_DIR ,
50+ DriverPool::FILE
51+ )->getAbsolutePath ();
52+ }
53+
3154 /**
3255 * Create cache adapter.
3356 *
@@ -47,6 +70,8 @@ public function create(string $adapter, array $config = []): CacheInterface
4770 return new Predis (new Client ($ config ), self ::CACHE_KEY , self ::CACHE_EXPIRATION );
4871 case self ::ADAPTER_MEMORY :
4972 return new Memory ();
73+ case self ::ADAPTER_LOCAL :
74+ return new Adapter (new Local ($ this ->localCacheRoot ), self ::CACHE_FILE , self ::CACHE_EXPIRATION );
5075 }
5176
5277 throw new DriverException (__ ('Cache adapter %1 is not supported ' , $ adapter ));
0 commit comments