角度2のカスタムキャッシュコントロール用のツールはありますか?ローカルストレージ?角度2のカスタムキャッシング/ローカルストレージ
Went through docs、参考までに見つかりませんでした。
一時的な解決策として、jQueryを使用する可能性がありますが、使用するポイントは何角ですか?
ごあいさつ
角度2のカスタムキャッシュコントロール用のツールはありますか?ローカルストレージ?角度2のカスタムキャッシング/ローカルストレージ
Went through docs、参考までに見つかりませんでした。
一時的な解決策として、jQueryを使用する可能性がありますが、使用するポイントは何角ですか?
ごあいさつ
あなたもこれを調べることができます。これはAngular2の状態管理プロバイダです。状態管理のために - あなたの条件の気圧のためにその適切であれば、私は私が@micronyksに同意し、角度のアプリを開発しながら@ngrx/storeは必携のパッケージであることを信じて、
を知りません。 Cached
方法デコレータとcaching APIを使用してキャッシュ方法(has
、get
、set
)が含まれてい@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'));
ここでは、パッケージのリストには、両方のクライアント側とサーバー側のキャッシュのために、以下のとおりです。
あなたはブラウザの 'localStorage'を考慮しましたか? –
私は以前は角度1でツールを提供していましたが、バージョン2のようなものは見つかりませんでした。 – nelly2k
あなたは 'angular2'で' $ cacheFactory 'を探しています。私もそれを見つけることができませんでした。しかし、[this](http://stackoverflow.com/questions/19304435/local-storage-vs-angularjs-cachefactory)の質問が役に立ちます。 –