Skip to content

Commit

Permalink
feat: 🎸 add http cache storage
Browse files Browse the repository at this point in the history
  • Loading branch information
Netanel Basal committed Feb 11, 2020
1 parent de87dd9 commit 07bcb4b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,11 @@ export class LocalStorageTTLManager {
return true;
}

const ttlValue = getStorageCache(this.ttlStorageKey).get(key);
const validInStorage = ttlValue > new Date().getTime();
const localStorageTimeStamp = getStorageCache(this.ttlStorageKey).get(key);
const validInStorage = localStorageTimeStamp > new Date().getTime();

if (validInStorage) {
this.ttl.set(key, ttlValue);
this.ttl.set(key, localStorageTimeStamp - new Date().getTime());
}

return validInStorage;
Expand All @@ -34,7 +35,7 @@ export class LocalStorageTTLManager {
const storage = getStorageCache(this.ttlStorageKey);
storage.set(key, new Date().setMilliseconds(resolveTTL));
setCacheInStorage(this.ttlStorageKey, storage);
this.ttl.set(key, ttl);
this.ttl.set(key, resolveTTL);
}

delete(key?: string | RegExp) {
Expand Down
2 changes: 1 addition & 1 deletion src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { HttpCacheInterceptorModule, useHttpCacheLocalStorage } from '@ngneat/ca

@NgModule({
declarations: [AppComponent, HomeComponent, TodosComponent],
providers: [useHttpCacheLocalStorage],
// providers: [useHttpCacheLocalStorage],
imports: [BrowserModule, AppRoutingModule, HttpClientModule, HttpCacheInterceptorModule.forRoot()],
bootstrap: [AppComponent]
})
Expand Down

0 comments on commit 07bcb4b

Please sign in to comment.