import {Injectable} from '@angular/core';

@Injectable({
    providedIn: 'root'
})

export class CacheService {

    constructor() {
    }

    /**
     * Gets item
     * @param key
     */
    public getItem(key: string): any {
        return localStorage.getItem(key) ? JSON.parse(localStorage.getItem(key)) : null;
    }

    /**
     * Sets item
     * @param key
     * @param item
     */
    public setItem(key: string, item: any): void {
        localStorage.setItem(key, JSON.stringify(item));
    }

    /**
     * Removes item
     * @param key
     */
    public removeItem(key): void {
        localStorage.removeItem(key);
    }
}
