0

からデータを保存/取得するための自動化された方法を設計したいと考えていますcache。これが、そのためのアーキテクチャを設計したい方法です。

2つのクラスライブラリがあります

DB.DataAccess -> このレイヤーは、ado.net を使用して sp/quires を実行し、データベースからデータにアクセスします。

DB.DataDistributor -> これは、データベースとプレゼンテーション層の間の中間層になり、DB.DataAccess を呼び出してデータを取得します

DB.DataDistributor では、カスタム属性を使用して、このようにデータ キャッシングを自動化したいと考えています。

namespace DB.DataDistributor
{
    public class MessageManager
    {


        [CachDataAttribute(CacheKey = CacheKeys.Message, CacheDataType = typeof(List<Message>))]
        public List<Message> GetMessages()
        {
            DB.DataAccess.MesssageManager msgManager = null;
            try
            {
                msgManager = new DB.DataAccess.MesssageManager();
                var messages = msgManager.GetMessages();
                return messages;
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                msgManager = null;
            }
        }


    }
}

namespace DB.DataDistributor
{
    [AttributeUsage(AttributeTargets.Method)]
    internal class DataCachingFilterAttribute : Attribute
    {
        public CacheKeys CacheKey { get; set; }
        public Type CacheDataType { get; set; }

        public void SetCache()
        {
            //this method should call after execution of method where DataCachingFilterAttribute has attached 
        }

        public void GetCache()
        {
            //this method should call before execution of method where DataCachingFilterAttribute has attached
            //here I will check if data available in cache then will return data from cache and do not call the achtual method 
        }
    }

    public enum CacheKeys
    {
        Message
    }
}
  • プレゼンテーション層がシステムの GetMessagesメソッドを 呼び出すときはいつでも、データがキャッシュにある場合はクラスのメソッドを実行する必要があり、実際のメソッドは実行されるべきではなく、データはキャッシュから直接返され、それ以外の場合は呼び出され、そこからデータが返されます。DB.DataDistributor.MessageManagerGetCache()DataCachingFilterAttributeGetMessagesGetMessages

  • メソッド から返されGetMessagesた結果の直後に、結果をキャッシュに設定するために呼び出す必要があります。SetCacheDataCachingFilterAttribute

これはデータ キャッシングを自動化するための私の考えですが、メソッド実行のDataCachingFilterAttribute前後にメソッドをトリガーする方法がわかりませんGetMessages

誰かがキャッシュを自動化するためのアイデアや他の良いアプローチを持っている場合は、共有してください。

4

0 に答える 0