Caching Patterns in ASP.NET

后端 未结 3 1907
隐瞒了意图╮
隐瞒了意图╮ 2021-01-30 18:51

So I just fixed a bug in a framework I\'m developing. The pseudo-pseudocode looks like this:

myoldObject = new MyObject { someValue = \"old value\" };
cache.Inse         


        
3条回答
  •  太阳男子
    2021-01-30 19:08

    Dirty tracking is the normal way to handle this, I think. Something like:

    class MyObject {
      public string SomeValue { 
         get { return _someValue; }
         set { 
           if (value != SomeValue) {
              IsDirty = true;
              _someValue = value;
           }
      }
    
      public bool IsDirty {
         get;
         private set;
      }
    
      void SaveToDatabase() {
         base.SaveToDatabase(); 
         IsDirty = false;
      }
    }
    
    myoldObject = new MyObject { someValue = "old value" };
    cache.Insert("myObjectKey", myoldObject);
    myNewObject = cache.Get("myObjectKey");
    myNewObject.someValue = "new value";
    if(myNewObject.IsDirty)
       myNewObject.SaveToDatabase();
    

提交回复
热议问题