7.1.0 • Published 5 years ago

@bizappframework/ng-cache v7.1.0

Weekly downloads
1
License
MIT
Repository
github
Last release
5 years ago

ng-cache

npm version Gitter

Contains cache services for Angular app.

Installation

npm install @bizappframework/ng-cache

Setup

import { CacheLocalStorageModule, CacheModule, MemoryCacheModule } from '@bizappframework/ng-cache';

@NgModule({
    imports: [
        // Other module imports

        // Caching
        CacheModule,
        CacheLocalStorageModule,
        MemoryCacheModule
    ]
})
export class AppModule { }

Usage

import { HttpClient, HttpResponse } from '@angular/common/http';
import { Inject, Injectable } from '@angular/core';

import { CacheEntryOptions, CacheService, handleCacheResponse } from '@bizappframework/ng-cache';
import { Observable } from 'rxjs/Observable';
import { map } from 'rxjs/operators';

import { BASE_URL } from './tokens';

export enum UserCacheKeys {
    Users = 'users',
    UsersCacheInfo = 'users.cacheinfo',
}

@Injectable()
export class UserService {

    constructor(
        private readonly _cacheService: CacheService,
        private readonly _httpClient: HttpClient,
        @Inject(BASE_URL) private readonly _baseUrl: string) {
    }

    getUsers(): Observable<string[]> {
        return this._cacheService.getOrSet(UserCacheKeys.Users,
            (entryOptions: CacheEntryOptions) => {
                const endpointUrl = `${this._baseUrl}/api/users`;

                return this._httpClient.get(endpointUrl, { observe: 'response' }).pipe(map(
                    (response: HttpResponse<string[]>) => {
                        return handleCacheResponse<string[]>(response, UserCacheKeys.UsersCacheInfo, entryOptions);
                    }));
            });
    }
}

Example

ng-cache-aspnetcore-sample

License

MIT License

7.1.0

5 years ago

7.0.0

6 years ago

6.1.3

6 years ago

6.1.2

6 years ago

6.1.1

6 years ago

6.1.0

6 years ago

6.0.0-beta.1

6 years ago

6.0.0-beta.0

6 years ago

5.0.0-beta.6

6 years ago

5.0.0-beta.5

6 years ago

5.0.0-beta.4

6 years ago

5.0.0-beta.3

6 years ago

5.0.0-beta.2

6 years ago

5.0.0-beta.1

6 years ago

5.0.0-beta.0

6 years ago