Skip to content

Instantly share code, notes, and snippets.

@gorkemyontem
Last active December 5, 2018 14:08
Show Gist options
  • Save gorkemyontem/2e5dbfac8158a355968638eadf4441f6 to your computer and use it in GitHub Desktop.
Save gorkemyontem/2e5dbfac8158a355968638eadf4441f6 to your computer and use it in GitHub Desktop.
import { InMemoryCacheService } from './in-memory-cache.service';
export const IN_MEMORY_CACHE_PROVIDERS = [
InMemoryCacheService
];
import { Injectable } from '@angular/core';
export let inMemoryCache = {};
@Injectable()
export class InMemoryCacheService {
public has(key: string): boolean {
return inMemoryCache[key] !== null;
}
public get(key: string): any {
return inMemoryCache[key] || null;
}
public set(key: string, value: any): void {
inMemoryCache[key] = value;
}
public remove(key: string): void {
delete inMemoryCache[key];
}
public clear(): void {
inMemoryCache = {};
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment