Skip to content

Commit e84af6a

Browse files
[DURACOM-350] fix cache issue after mydspace action
1 parent b076738 commit e84af6a

File tree

3 files changed

+10
-2
lines changed

3 files changed

+10
-2
lines changed

src/app/shared/mydspace-actions/mydspace-actions.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,13 +101,17 @@ export abstract class MyDSpaceActionsComponent<T extends DSpaceObject, TService
101101
reload(): void {
102102

103103
this.router.navigated = false;
104-
const url = decodeURIComponent(this.router.url);
105104
// override the route reuse strategy
106105
this.router.routeReuseStrategy.shouldReuseRoute = () => {
107106
return false;
108107
};
109108
// This assures that the search cache is empty before reloading mydspace.
110109
// See https://github.com/DSpace/dspace-angular/pull/468
110+
this.invalidateCacheForCurrentSearchUrl();
111+
}
112+
113+
invalidateCacheForCurrentSearchUrl(): void {
114+
const url = decodeURIComponent(this.router.url);
111115
this.searchService.getEndpoint().pipe(
112116
take(1),
113117
tap((cachedHref: string) => this.requestService.removeByHrefSubstring(cachedHref)),

src/app/shared/mydspace-actions/mydspace-reloadable-actions.spec.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,7 @@ describe('MyDSpaceReloadableActionsComponent', () => {
219219
spyOn(component, 'reloadObjectExecution').and.callThrough();
220220
spyOn(component, 'convertReloadedObject').and.callThrough();
221221
spyOn(component.processCompleted, 'emit').and.callThrough();
222+
spyOn(component, 'invalidateCacheForCurrentSearchUrl').and.callThrough();
222223

223224
(component as any).objectDataService = mockDataService;
224225
});
@@ -239,10 +240,11 @@ describe('MyDSpaceReloadableActionsComponent', () => {
239240
});
240241
});
241242

242-
it('should emit the reloaded object in case of success', (done) => {
243+
it('should emit the reloaded object and invalidate cache in case of success', (done) => {
243244

244245
component.startActionExecution().subscribe( (result) => {
245246
expect(component.processCompleted.emit).toHaveBeenCalledWith({ result: true, reloadedObject: result as any });
247+
expect(component.invalidateCacheForCurrentSearchUrl).toHaveBeenCalled();
246248
done();
247249
});
248250
});

src/app/shared/mydspace-actions/mydspace-reloadable-actions.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,8 @@ export abstract class MyDSpaceReloadableActionsComponent<T extends DSpaceObject,
105105
if (result) {
106106
if (reloadedObject) {
107107
this.processCompleted.emit({ result, reloadedObject });
108+
// Ensure that next time the page is requested the objects have the correct render type.
109+
this.invalidateCacheForCurrentSearchUrl();
108110
} else {
109111
this.reload();
110112
}

0 commit comments

Comments
 (0)