@@ -42,6 +42,8 @@ type PluginManager struct {
4242
4343 config * app.Config
4444
45+ pluginAssetCache * lru.Cache [string , []byte ]
46+
4547 // plugin lifecycle controller
4648 //
4749 // whatever it's local mode or serverless mode, all the signals and calls
@@ -71,10 +73,16 @@ func InitGlobalManager(oss oss.OSS, config *app.Config) *PluginManager {
7173 config .PluginPackageCachePath ,
7274 )
7375
76+ pluginAssetCache , err := lru.New [string , []byte ](int (config .PluginAssetCacheSize ))
77+ if err != nil {
78+ log .Panic ("init plugin asset cache failed" , "error" , err )
79+ }
80+
7481 manager = & PluginManager {
75- mediaBucket : mediaBucket ,
76- packageBucket : packageBucket ,
77- installedBucket : installedBucket ,
82+ mediaBucket : mediaBucket ,
83+ packageBucket : packageBucket ,
84+ installedBucket : installedBucket ,
85+ pluginAssetCache : pluginAssetCache ,
7886 controlPanel : controlpanel .NewControlPanel (
7987 config ,
8088 mediaBucket ,
@@ -196,26 +204,23 @@ func (c *PluginManager) NeedRedirecting(
196204 return true , nil
197205}
198206
199- var (
200- pluginAssetCache * lru.Cache [string , []byte ]
201- )
202-
203207func pluginAssetCacheKey (
204208 pluginUniqueIdentifier plugin_entities.PluginUniqueIdentifier ,
205209 path string ,
206210) string {
207211 return fmt .Sprintf ("%s/%s" , pluginUniqueIdentifier .String (), path )
208212}
213+
209214func (p * PluginManager ) ExtractPluginAsset (
210215 pluginUniqueIdentifier plugin_entities.PluginUniqueIdentifier ,
211216 path string ,
212217) ([]byte , error ) {
213218 key := pluginAssetCacheKey (pluginUniqueIdentifier , path )
214- cached , ok := pluginAssetCache .Get (key )
219+ cached , ok := p . pluginAssetCache .Get (key )
215220 if ok {
216221 return cached , nil
217222 }
218- pkgBytes , err := manager .GetPackage (pluginUniqueIdentifier )
223+ pkgBytes , err := p .GetPackage (pluginUniqueIdentifier )
219224 if err != nil {
220225 return nil , err
221226 }
@@ -227,6 +232,6 @@ func (p *PluginManager) ExtractPluginAsset(
227232 if err != nil {
228233 return nil , err
229234 }
230- pluginAssetCache .Add (key , assets [path ])
235+ p . pluginAssetCache .Add (key , assets [path ])
231236 return assets [path ], nil
232237}
0 commit comments