openaire-library/services/clear-cache.service.ts

32 lines
1.1 KiB
TypeScript

import {Injectable} from "@angular/core";
import {HttpClient} from "@angular/common/http";
import {properties} from "../../../environments/environment";
import {CustomOptions} from "./servicesUtils/customOptions.class";
@Injectable({
providedIn: 'root'
})
export class ClearCacheService {
constructor(private http: HttpClient) {}
clearCache(message: string = null) {
if(properties.deleteCacheUrl) {
this.http.get(properties.deleteCacheUrl).subscribe(
res => console.log((message ? message + ": " : "") + "Cache cleared!"),
err => console.log((message ? message + ": " : "") + "Cache could not be cleared ", err)
);
}
}
purgeBrowserCache(message: string = null, pid: string) {
if(properties.deleteBrowserCacheUrl) {
let url = properties.deleteBrowserCacheUrl + "/" + pid;
this.http.get(url, CustomOptions.registryOptions()).subscribe(
res => console.log((message ? message + ": " : "") + "Browser Cache purged!"),
err => console.log((message ? message + ": " : "") + "Browser Cache could not be purged ", err)
);
}
}
}