2016-03-22 15 views
0

角度2のカスタムキャッシュコントロール用のツールはありますか?ローカルストレージ?角度2のカスタムキャッシング/ローカルストレージ

Went through docs、参考までに見つかりませんでした。

一時的な解決策として、jQueryを使用する可能性がありますが、使用するポイントは何角ですか?

ごあいさつ

+0

あなたはブラウザの 'localStorage'を考慮しましたか? –

+0

私は以前は角度1でツールを提供していましたが、バージョン2のようなものは見つかりませんでした。 – nelly2k

+1

あなたは 'angular2'で' $ cacheFactory 'を探しています。私もそれを見つけることができませんでした。しかし、[this](http://stackoverflow.com/questions/19304435/local-storage-vs-angularjs-cachefactory)の質問が役に立ちます。 –

答えて

0

あなたもこれを調べることができます。これはAngular2の状態管理プロバイダです。状態管理のために - あなたの条件の気圧のためにその適切であれば、私は私が@micronyksに同意し、角度のアプリを開発しながら@ngrx/storeは必携のパッケージであることを信じて、

https://github.com/ngrx/store

0

を知りません。 Cached方法デコレータとcaching APIを使用してキャッシュ方法(hasgetset)が含まれてい@ngx-cache/core

はしかし、私は、キャッシュ管理のためのより適切なパッケージがあります信じています。

anyclass.ts

... 
import { CacheService } from '@ngx-cache/core'; 

@Injectable() 
export class AnyClass { 
    constructor(private readonly cache: CacheService) { 
    // note that CacheService is injected into a private property of AnyClass 
    } 

    // will retrieve 'some string value' 
    getSomeStringValue(): string { 
    if (this.cache.has('some-string')) 
     return this.cache.get('some-string'); 

    this.cache.set('some-string', 'some string value'); 
    return 'some string value'; 
    } 
} 

この例Cached方法デコレータの使用を示しており、CacheKey paramsはデコレータ:

次の例では、APIメソッドの使用を示していますanyclass.ts

... 
import { Cached, CacheKey } from '@ngx-cache/core'; 

export class AnyClass { 
    // will retrieve 'some string value' 
    @Cached('some-string') 
    getSomeStringValue(): string { 
    return 'some string value'; 
    } 

    @Cached('some-string') 
    getSomeStringValue2(@CacheKey param1: string): string { 
    return 'some string value: ' + param1; 
    } 
} 

... 
// these are the first executions 
console.log(anyClass.getSomeStringValue2('p1')); 
console.log(anyClass.getSomeStringValue2('p2')); 
... 
// will retrieve 'some string value: p1' from `CACHE` 
console.log(anyClass.getSomeStringValue2('p1')); 

// will retrieve 'some string value: p1' from `CACHE` 
console.log(anyClass.getSomeStringValue2('p2')); 

ここでは、パッケージのリストには、両方のクライアント側とサーバー側のキャッシュのために、以下のとおりです。