Memory cached generic list removing without effect cached list









up vote
1
down vote

favorite












I am trying remove one item from my list.BUT, I am getting the list from cache.
After this I am removing one item in my fuction. This removing effect my cached list.If I try again to get cached list from cache in another page. Removed item is missing how is this possible ?



example ,



var IList list;
if(condition)

list=CacheManagement.GetFromCache();
else
list=SqlManagement.GetFromSql();


list.removeall(x=>x.id==1);
//end of my function









share|improve this question



























    up vote
    1
    down vote

    favorite












    I am trying remove one item from my list.BUT, I am getting the list from cache.
    After this I am removing one item in my fuction. This removing effect my cached list.If I try again to get cached list from cache in another page. Removed item is missing how is this possible ?



    example ,



    var IList list;
    if(condition)

    list=CacheManagement.GetFromCache();
    else
    list=SqlManagement.GetFromSql();


    list.removeall(x=>x.id==1);
    //end of my function









    share|improve this question

























      up vote
      1
      down vote

      favorite









      up vote
      1
      down vote

      favorite











      I am trying remove one item from my list.BUT, I am getting the list from cache.
      After this I am removing one item in my fuction. This removing effect my cached list.If I try again to get cached list from cache in another page. Removed item is missing how is this possible ?



      example ,



      var IList list;
      if(condition)

      list=CacheManagement.GetFromCache();
      else
      list=SqlManagement.GetFromSql();


      list.removeall(x=>x.id==1);
      //end of my function









      share|improve this question















      I am trying remove one item from my list.BUT, I am getting the list from cache.
      After this I am removing one item in my fuction. This removing effect my cached list.If I try again to get cached list from cache in another page. Removed item is missing how is this possible ?



      example ,



      var IList list;
      if(condition)

      list=CacheManagement.GetFromCache();
      else
      list=SqlManagement.GetFromSql();


      list.removeall(x=>x.id==1);
      //end of my function






      c# memcached generic-list






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 10 at 21:31

























      asked Nov 10 at 20:57









      Alican Kablan

      115210




      115210






















          1 Answer
          1






          active

          oldest

          votes

















          up vote
          2
          down vote



          accepted










          So when you make a change to list, it is reflected to the cache, that is because the reference (memory address of the list) is copied to cache, so any changes would actually be reflected in the cache.



          To avoid it simply put a Clone() of your list to the cache. (assuming UpdateCache() is the method that sets the cache) you can do it like this:



          UpdateCache(list.Clone());





          share|improve this answer






















          • no sir you understand me false maybe my explaining is wrong sorry.I am only getting list from cache and editing in code.I never update my cache after edit.UPDATE! I have update my question it was wrong.
            – Alican Kablan
            Nov 10 at 21:30











          • so thats why when you load from cache it comes back. I know Turkish if you like we can continue discussion in chat
            – uɐʞɥsɐ
            Nov 10 at 21:33










          • I would be very pleased.Please.
            – Alican Kablan
            Nov 10 at 21:35






          • 1




            @AlicanKablan I updated my answer.
            – uɐʞɥsɐ
            Nov 10 at 22:02










          • When you get the object from memory cache you are editing the actual object in the cache not a copy of it. this is why when you remove in the code you are removing the item from the list in the cache as well. this is happening just for the memory cache (heap memory) and careful if you have more than one server at the production line you will loose the consistency on the cache.
            – Meysam
            Dec 6 at 17:37










          Your Answer






          StackExchange.ifUsing("editor", function ()
          StackExchange.using("externalEditor", function ()
          StackExchange.using("snippets", function ()
          StackExchange.snippets.init();
          );
          );
          , "code-snippets");

          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "1"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













          draft saved

          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53243344%2fmemory-cached-generic-list-removing-without-effect-cached-list%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes








          up vote
          2
          down vote



          accepted










          So when you make a change to list, it is reflected to the cache, that is because the reference (memory address of the list) is copied to cache, so any changes would actually be reflected in the cache.



          To avoid it simply put a Clone() of your list to the cache. (assuming UpdateCache() is the method that sets the cache) you can do it like this:



          UpdateCache(list.Clone());





          share|improve this answer






















          • no sir you understand me false maybe my explaining is wrong sorry.I am only getting list from cache and editing in code.I never update my cache after edit.UPDATE! I have update my question it was wrong.
            – Alican Kablan
            Nov 10 at 21:30











          • so thats why when you load from cache it comes back. I know Turkish if you like we can continue discussion in chat
            – uɐʞɥsɐ
            Nov 10 at 21:33










          • I would be very pleased.Please.
            – Alican Kablan
            Nov 10 at 21:35






          • 1




            @AlicanKablan I updated my answer.
            – uɐʞɥsɐ
            Nov 10 at 22:02










          • When you get the object from memory cache you are editing the actual object in the cache not a copy of it. this is why when you remove in the code you are removing the item from the list in the cache as well. this is happening just for the memory cache (heap memory) and careful if you have more than one server at the production line you will loose the consistency on the cache.
            – Meysam
            Dec 6 at 17:37














          up vote
          2
          down vote



          accepted










          So when you make a change to list, it is reflected to the cache, that is because the reference (memory address of the list) is copied to cache, so any changes would actually be reflected in the cache.



          To avoid it simply put a Clone() of your list to the cache. (assuming UpdateCache() is the method that sets the cache) you can do it like this:



          UpdateCache(list.Clone());





          share|improve this answer






















          • no sir you understand me false maybe my explaining is wrong sorry.I am only getting list from cache and editing in code.I never update my cache after edit.UPDATE! I have update my question it was wrong.
            – Alican Kablan
            Nov 10 at 21:30











          • so thats why when you load from cache it comes back. I know Turkish if you like we can continue discussion in chat
            – uɐʞɥsɐ
            Nov 10 at 21:33










          • I would be very pleased.Please.
            – Alican Kablan
            Nov 10 at 21:35






          • 1




            @AlicanKablan I updated my answer.
            – uɐʞɥsɐ
            Nov 10 at 22:02










          • When you get the object from memory cache you are editing the actual object in the cache not a copy of it. this is why when you remove in the code you are removing the item from the list in the cache as well. this is happening just for the memory cache (heap memory) and careful if you have more than one server at the production line you will loose the consistency on the cache.
            – Meysam
            Dec 6 at 17:37












          up vote
          2
          down vote



          accepted







          up vote
          2
          down vote



          accepted






          So when you make a change to list, it is reflected to the cache, that is because the reference (memory address of the list) is copied to cache, so any changes would actually be reflected in the cache.



          To avoid it simply put a Clone() of your list to the cache. (assuming UpdateCache() is the method that sets the cache) you can do it like this:



          UpdateCache(list.Clone());





          share|improve this answer














          So when you make a change to list, it is reflected to the cache, that is because the reference (memory address of the list) is copied to cache, so any changes would actually be reflected in the cache.



          To avoid it simply put a Clone() of your list to the cache. (assuming UpdateCache() is the method that sets the cache) you can do it like this:



          UpdateCache(list.Clone());






          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Nov 10 at 22:01

























          answered Nov 10 at 21:01









          uɐʞɥsɐ

          19.9k1565114




          19.9k1565114











          • no sir you understand me false maybe my explaining is wrong sorry.I am only getting list from cache and editing in code.I never update my cache after edit.UPDATE! I have update my question it was wrong.
            – Alican Kablan
            Nov 10 at 21:30











          • so thats why when you load from cache it comes back. I know Turkish if you like we can continue discussion in chat
            – uɐʞɥsɐ
            Nov 10 at 21:33










          • I would be very pleased.Please.
            – Alican Kablan
            Nov 10 at 21:35






          • 1




            @AlicanKablan I updated my answer.
            – uɐʞɥsɐ
            Nov 10 at 22:02










          • When you get the object from memory cache you are editing the actual object in the cache not a copy of it. this is why when you remove in the code you are removing the item from the list in the cache as well. this is happening just for the memory cache (heap memory) and careful if you have more than one server at the production line you will loose the consistency on the cache.
            – Meysam
            Dec 6 at 17:37
















          • no sir you understand me false maybe my explaining is wrong sorry.I am only getting list from cache and editing in code.I never update my cache after edit.UPDATE! I have update my question it was wrong.
            – Alican Kablan
            Nov 10 at 21:30











          • so thats why when you load from cache it comes back. I know Turkish if you like we can continue discussion in chat
            – uɐʞɥsɐ
            Nov 10 at 21:33










          • I would be very pleased.Please.
            – Alican Kablan
            Nov 10 at 21:35






          • 1




            @AlicanKablan I updated my answer.
            – uɐʞɥsɐ
            Nov 10 at 22:02










          • When you get the object from memory cache you are editing the actual object in the cache not a copy of it. this is why when you remove in the code you are removing the item from the list in the cache as well. this is happening just for the memory cache (heap memory) and careful if you have more than one server at the production line you will loose the consistency on the cache.
            – Meysam
            Dec 6 at 17:37















          no sir you understand me false maybe my explaining is wrong sorry.I am only getting list from cache and editing in code.I never update my cache after edit.UPDATE! I have update my question it was wrong.
          – Alican Kablan
          Nov 10 at 21:30





          no sir you understand me false maybe my explaining is wrong sorry.I am only getting list from cache and editing in code.I never update my cache after edit.UPDATE! I have update my question it was wrong.
          – Alican Kablan
          Nov 10 at 21:30













          so thats why when you load from cache it comes back. I know Turkish if you like we can continue discussion in chat
          – uɐʞɥsɐ
          Nov 10 at 21:33




          so thats why when you load from cache it comes back. I know Turkish if you like we can continue discussion in chat
          – uɐʞɥsɐ
          Nov 10 at 21:33












          I would be very pleased.Please.
          – Alican Kablan
          Nov 10 at 21:35




          I would be very pleased.Please.
          – Alican Kablan
          Nov 10 at 21:35




          1




          1




          @AlicanKablan I updated my answer.
          – uɐʞɥsɐ
          Nov 10 at 22:02




          @AlicanKablan I updated my answer.
          – uɐʞɥsɐ
          Nov 10 at 22:02












          When you get the object from memory cache you are editing the actual object in the cache not a copy of it. this is why when you remove in the code you are removing the item from the list in the cache as well. this is happening just for the memory cache (heap memory) and careful if you have more than one server at the production line you will loose the consistency on the cache.
          – Meysam
          Dec 6 at 17:37




          When you get the object from memory cache you are editing the actual object in the cache not a copy of it. this is why when you remove in the code you are removing the item from the list in the cache as well. this is happening just for the memory cache (heap memory) and careful if you have more than one server at the production line you will loose the consistency on the cache.
          – Meysam
          Dec 6 at 17:37

















          draft saved

          draft discarded
















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          To learn more, see our tips on writing great answers.





          Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


          Please pay close attention to the following guidance:


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53243344%2fmemory-cached-generic-list-removing-without-effect-cached-list%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Use pre created SQLite database for Android project in kotlin

          Darth Vader #20

          Ondo