0

I have some Json Formated records (over 10000) fetched from Database in this Json format:

 {\"ID\":7701,\"Lat\":36.78332170249675,\"Lng\":45.729067325592041}

In ASP.net MVC I want to save data in Ram or Cache to prevent Data Retrieval. But I could not save it in Cache, I think it's because of Cache limit.

What do you suggest me to? Not to re-Reading data from SQL Server Database?

===================== Below code of Saving in Cache

ObjectCache cache = MemoryCache.Default;
        CacheItemPolicy policy = new CacheItemPolicy()
        {
            Priority = CacheItemPriority.Default,
            AbsoluteExpiration = System.DateTimeOffset.UtcNow.AddMilliseconds(RefreshInterval)
        };
        cache.Set(id, JsonConvert.SerializeObject(listOfData,new JsonSerializerSettings { ReferenceLoopHandling = ReferenceLoopHandling.Ignore }) , policy);

for reading I use this code:

foreach (var item in MemoryCache.Default)
            {

                string key = item.Key;

                if (key == id)
                {
                    var w = JsonConvert.DeserializeObject(item.Value, typeof(List<SOME>)) as List<SOME>;

                }
            }
Sajjad.HS
  • 381
  • 2
  • 8
  • 19
  • 1
    Why can't you save it in cache? What kind of error did you get? If you looking for some other solutions check this out: https://stackoverflow.com/questions/14047619/asp-net-caching-limit – SehaxX Jun 28 '18 at 14:01
  • There is no error when saving, but when I try to read it from cache it wont be there. So it's not saved. @SehaxX – Sajjad.HS Jun 28 '18 at 14:03
  • 1
    How about some code? Just saying it isn't in the cache is useless. Maybe you put in the cache incorrectly, maybe you try to retrieve it incorrectly, maybe any number of things. – Sean Lange Jun 28 '18 at 14:17
  • I put some code of setting in cache in my post.@SeanLange – Sajjad.HS Jun 28 '18 at 15:18
  • I even tested "memcached" now, it works but it take more than database query time :( @SehaxX – Sajjad.HS Jun 28 '18 at 15:19

0 Answers0