@@ -34,6 +34,8 @@ export default new Vuex.Store({
3434 description : "" ,
3535 } ,
3636 migratingApps : [ ] ,
37+ taskContextCache : new Map ( ) ,
38+ taskContextCacheSize : 50 , //// 50?
3739 } ,
3840 getters : {
3941 unreadNotifications : ( state , getters ) => {
@@ -190,6 +192,37 @@ export default new Vuex.Store({
190192 setMigratingApps ( state , migratingApps ) {
191193 state . migratingApps = migratingApps ;
192194 } ,
195+ refreshTaskContextInCache ( state , payload ) {
196+ console . log ( "@@ refreshTaskContextInCache" , payload ) ; ////
197+
198+ const taskId = payload . taskId ;
199+ const taskContext = payload . taskContext ;
200+
201+ // Refresh the item: delete and re-insert so it's "newest"
202+ state . taskContextCache . delete ( taskId ) ;
203+ state . taskContextCache . set ( taskId , taskContext ) ;
204+ } ,
205+ setTaskContextInCache ( state , payload ) {
206+ console . log ( "@@ setTaskContextInCache" , payload ) ; ////
207+
208+ const taskId = payload . taskId ;
209+ const taskContext = payload . taskContext ;
210+
211+ // If it already exists, delete it first to update the position
212+ if ( state . taskContextCache . has ( taskId ) ) {
213+ state . taskContextCache . delete ( taskId ) ;
214+ }
215+
216+ // Remove the oldest entry if limit is reached
217+ // .keys().next().value returns the first (oldest) key
218+ if ( state . taskContextCache . size >= state . taskContextCacheSize ) {
219+ const oldestKey = state . taskContextCache . keys ( ) . next ( ) . value ;
220+ state . taskContextCache . delete ( oldestKey ) ;
221+
222+ console . log ( "@@ deleted old key" , oldestKey ) ; ////
223+ }
224+ state . taskContextCache . set ( taskId , taskContext ) ;
225+ } ,
193226 } ,
194227 actions : {
195228 setPollingTimerForTaskInStore ( context , obj ) {
@@ -282,6 +315,23 @@ export default new Vuex.Store({
282315 setMigratingAppsInStore ( context , migratingApps ) {
283316 context . commit ( "setMigratingApps" , migratingApps ) ;
284317 } ,
318+ getTaskContextFromCache : ( context , taskId ) => {
319+ console . log ( "@@ getTaskContextFromCache" , taskId ) ; ////
320+
321+ if ( ! context . state . taskContextCache . has ( taskId ) ) {
322+ console . log ( "@@ cache MISS" , taskId ) ; ////
323+
324+ // The requested task ID is not in the cache
325+ return null ;
326+ }
327+ const taskContext = context . state . taskContextCache . get ( taskId ) ;
328+
329+ console . log ( "@@ cache HIT" , taskId , taskContext ) ; ////
330+
331+ // Refresh the item: delete and re-insert so it's "newest"
332+ context . commit ( "refreshTaskContextInCache" , { taskId, taskContext } ) ;
333+ return taskContext ;
334+ } ,
285335 } ,
286336} ) ;
287337
0 commit comments