Skip to content

Commit

Permalink
fix(cache-flow): dynamically override cached data
Browse files Browse the repository at this point in the history
Because post flow will dynamically change cachePath, the action deleting cached data need to be
delayed to query stage
  • Loading branch information
ElonH committed Jun 2, 2020
1 parent fa96913 commit 2a927ee
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
10 changes: 7 additions & 3 deletions src/app/@dataflow/core/cache-flow.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { iif, Observable, of } from 'rxjs';
import { map, take, tap } from 'rxjs/operators';
import { take, tap } from 'rxjs/operators';
import { CombErr, FlowInNode, FlowOutNode } from './bare-flow';
import { FlowSupNode, SupersetFlow } from './superset-flow';

Expand All @@ -12,6 +12,8 @@ export abstract class CacheFlow<

protected abstract cacheSupport: boolean;
protected abstract cachePath: string | undefined;
protected cleanCacheFlag = false;

public static purgeAllCache() {
CacheFlow.cacheStorage = {};
}
Expand All @@ -33,7 +35,8 @@ export abstract class CacheFlow<
return this.cacheSupport && typeof this.cachePath === 'string';
}
private isCached() {
return CacheFlow.cacheStorage.hasOwnProperty(this.cachePath);
if (this.cleanCacheFlag) return !(this.cleanCacheFlag = true);
return !this.cleanCacheFlag && CacheFlow.cacheStorage.hasOwnProperty(this.cachePath);
}
private getCache(): CombErr<Tout> {
return CacheFlow.cacheStorage[this.cachePath] as CombErr<Tout>;
Expand All @@ -42,6 +45,7 @@ export abstract class CacheFlow<
CacheFlow.cacheStorage[this.cachePath] = x;
}
public clearCache() {
delete CacheFlow.cacheStorage[this.cachePath];
this.cleanCacheFlag = true;
// delete CacheFlow.cacheStorage[this.cachePath];
}
}
2 changes: 1 addition & 1 deletion src/app/@dataflow/rclone/list-group-flow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export abstract class ListGroupFlow extends PostFlow<IRcloneServer, ListGroupFlo
// public prerequest$: Observable<CombErr<IRcloneServer>>;
protected cmd = 'core/group-list';
protected params = {};
protected cacheSupport = false;
protected cacheSupport = true;
protected reconstructAjaxResult(x: AjaxFlowInteralNode): CombErr<ListGroupFlowOutNode> {
if (x[1].length !== 0) return [{}, x[1]] as any;
return [{ groups: x[0].ajaxRsp.response['groups'] }, []];
Expand Down
1 change: 1 addition & 0 deletions src/app/pages/jobs/jobs.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ export class JobsComponent implements OnInit, OnDestroy {
}

public refreshList() {
this.listGroup$.clearCache();
this.listTrigger.next(1);
}
ngOnDestroy() {
Expand Down

0 comments on commit 2a927ee

Please sign in to comment.