2020-09-24 13:18:24 +02:00
|
|
|
import {Injectable} from "@angular/core";
|
2024-04-03 09:26:29 +02:00
|
|
|
import {HttpClient, HttpHeaders} from "@angular/common/http";
|
2020-09-24 13:18:24 +02:00
|
|
|
import {properties} from "../../../environments/environment";
|
2022-08-11 14:46:55 +02:00
|
|
|
import {CustomOptions} from "./servicesUtils/customOptions.class";
|
2020-09-24 13:18:24 +02:00
|
|
|
|
|
|
|
@Injectable({
|
|
|
|
providedIn: 'root'
|
|
|
|
})
|
|
|
|
export class ClearCacheService {
|
|
|
|
|
|
|
|
constructor(private http: HttpClient) {}
|
|
|
|
|
2024-04-03 09:26:29 +02:00
|
|
|
|
|
|
|
clearCache(message: string = null, url:string = null) {
|
2022-08-08 13:14:43 +02:00
|
|
|
if(properties.deleteCacheUrl) {
|
2024-04-03 09:26:29 +02:00
|
|
|
this.http.get(properties.deleteCacheUrl + (url?'?url='+url:'')).subscribe(
|
2022-08-08 13:14:43 +02:00
|
|
|
res => console.log((message ? message + ": " : "") + "Cache cleared!"),
|
|
|
|
err => console.log((message ? message + ": " : "") + "Cache could not be cleared ", err)
|
2020-09-24 13:18:24 +02:00
|
|
|
);
|
2022-08-08 13:14:43 +02:00
|
|
|
}
|
2020-09-24 13:18:24 +02:00
|
|
|
}
|
2024-04-03 09:26:29 +02:00
|
|
|
clearCacheInRoute(message: string = null, pid:string, route:string = "/") {
|
|
|
|
let domain = "";
|
|
|
|
if(properties.environment == 'production' || properties.environment == 'beta') {
|
|
|
|
domain = 'https://' + (properties.environment == 'production' ? '' : 'beta.') + pid + '.openaire.eu';
|
|
|
|
}
|
|
|
|
domain = properties.connectPortalUrl;
|
|
|
|
this.http.get(domain + route + '?forceCacheReload=true',
|
|
|
|
{
|
|
|
|
headers: new HttpHeaders({
|
|
|
|
'Cache-Control': 'no-cache, no-store, must-revalidate',
|
|
|
|
'Pragma': 'no-cache',
|
|
|
|
'Expires': '0',
|
|
|
|
})
|
|
|
|
}).subscribe(
|
|
|
|
res => console.log((message ? message + ": " : "") + "Cache cleared!"),
|
|
|
|
err => console.log((message ? message + ": " : "") + "Cache could not be cleared ", err)
|
|
|
|
);
|
|
|
|
|
|
|
|
}
|
2022-08-11 11:58:20 +02:00
|
|
|
|
|
|
|
purgeBrowserCache(message: string = null, pid: string) {
|
|
|
|
if(properties.deleteBrowserCacheUrl) {
|
2022-08-11 14:46:55 +02:00
|
|
|
let url = properties.deleteBrowserCacheUrl + "/" + pid;
|
|
|
|
this.http.get(url, CustomOptions.registryOptions()).subscribe(
|
2022-08-11 11:58:20 +02:00
|
|
|
res => console.log((message ? message + ": " : "") + "Browser Cache purged!"),
|
|
|
|
err => console.log((message ? message + ": " : "") + "Browser Cache could not be purged ", err)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2020-09-24 13:18:24 +02:00
|
|
|
}
|