2016-08-18 19 views
0

私は、アプリケーションを開いたときにクライアントデスクトップアプリケーションにデータセットを返すWebサービスを持っています。 デスクトップアプリケーションには、このデータセットの全ライフタイムが必要ですデスクトップアプリケーションでデータセットを再利用するための最良の方法

このデータセットをASP.netのキャッシュのようなものに保つ最も良い方法は何ですか?

XMLとして保持し、アプリケーションがデータを検索するときに取り戻す可能性はありますか?

これはクライアントアプリケーションに供給される製品リストです。製品リストはWebアプリケーションからグローバルに更新されるため、クライアントに最新のデータが必要な場合、Webから取得する方法はありますが、アプリケーションと9000行は

サンプルコードをデータセットに消費されますどのくらいのメモリを確認してください、それを使用してますが、私は、アプリケーションのパフォーマンスとメモリが心配です9000行を持っていない保つには、多くのあなたが使用したい

+0

それはなぜそれが保存する必要がないアプリが起動するたびに送信された場合は? – Plutonix

+0

「ベストウェイ」に関する質問は、本当に答えにくいです。特に文脈があまりない場合は特にそうです。 –

答えて

1

を理解されるであろうキャッシュサイドパターン。

基本的には、キャッシュに具体的なオブジェクトを置くための有名な方法を提供しています.....有効期限ポリシー(ホイールを再発明しないでください)を使用してください。

パターンには、「キャッシュにあるものを教えてください。そうでなければ、オブジェクトに移動してオブジェクトを移入する実際の方法があります」と表示されます。

シンクライアント上で以下のコードを実行します。新しいClaimsPrincipalがある場合は、Webサービスを呼び出して必要なデータを取得します。ここで

https://msdn.microsoft.com/en-us/library/dn589799.aspx

https://blog.cdemi.io/design-patterns-cache-aside-pattern/

例です。

public class PrincipalMemoryCacheAside // : IPrincipalCacheAside 
    { 
     public const string CacheKeyPrefix = "PrincipalMemoryCacheAsideKey"; 

     public ClaimsPrincipal GetTheClaimsPrincipal(string uniqueIdentifier) 
     { 
      string cacheKey = this.GetFullCacheKey(uniqueIdentifier); 
      ClaimsPrincipal cachedOrFreshPrincipal = GetFromCache<ClaimsPrincipal>(
       cacheKey, 
       () => 
       { 
        ClaimsPrincipal returnPrinc = null; 

        /* You would go hit your web service here to populate your object */ 
        ClaimsIdentity ci = new GenericIdentity(this.GetType().ToString()); 
        ci.AddClaim(new Claim("MyType", "MyValue")); 
        returnPrinc = new ClaimsPrincipal(ci); 


        return returnPrinc; 
       }); 

      return cachedOrFreshPrincipal; 
     } 

     private TEntity GetFromCache<TEntity>(string key, Func<TEntity> valueFactory) where TEntity : class 
     { 

      ObjectCache cache = MemoryCache.Default; 
      //// the lazy class provides lazy initializtion which will evaluate the valueFactory expression only if the item does not exist in cache 
      var newValue = new Lazy<TEntity>(valueFactory); 
      CacheItemPolicy policy = new CacheItemPolicy { SlidingExpiration = new TimeSpan(0, 60, 0), Priority = CacheItemPriority.NotRemovable }; 
      ////The line below returns existing item or adds the new value if it doesn't exist 
      var value = cache.AddOrGetExisting(key, newValue, policy) as Lazy<TEntity>; 
      return (value ?? newValue).Value; // Lazy<T> handles the locking itself 
     } 

     private string GetFullCacheKey(string uniqueIdentifier) 
     { 
      string returnValue = CacheKeyPrefix + uniqueIdentifier; 
      return returnValue; 
     } 
    } 
関連する問題