Caching strategy

2019-08-17 00:17发布

i have a large list of static data from a server that i load on startup. I load this into a hashtable of foo objects. the user has a dropdown where they can choose one of these object. by default there are 50,000 objects which take up a lot of memory. i am trying to reduce memory

after monitoring usage, it turns out that most people only use about 1,000 of them. i want to have it so the gui only loads up those 1000 and if they need to select one that is outside that 1000 then they can go back to the server or to disk.

what would be the best way of doing this . .

5条回答
兄弟一词,经得起流年.
2楼-- · 2019-08-17 00:50

Depending on the nature of your data how about forgetting about the whole thing and leave it up to the OS? Put it in a memory-mapped file.

查看更多
We Are One
3楼-- · 2019-08-17 00:53

I'm assuming you're filtering this list elsewhere...otherwise that's quite a list. The easiest way to hit your new, leaner static cache before hitting the DB will be to pass all requests through a single method:

public yourClass GetDesiredObject(string lkupValue)
{
  if (yourCachedHashtable.ContainsKey(lkupValue))
  {
     return yourCachedHashtable[lkupValue]
  }
  else
  {
     //Hit the db to retrieve the object values.
     yourClass obj = yourDatabaseCode.GetNewObject(lkupValue);
     //Add to the cache if desired.
     yourCachedHashtable.Add(lkupValue, obj);
     return obj;
  }
}
查看更多
来,给爷笑一个
4楼-- · 2019-08-17 01:04

The problem with loading a 1000 first is

  1. Who would scroll a 1000?

  2. The going back to the disk will cause the dropdown to reset and they'll have to scroll again.

Solution

  1. Why not implement a auto search dropdown, and try caching app block, it works great for me with extensive amounts of data.

  2. Look at devexpress dropdown edit, you'll need to purchase their controls though.

查看更多
forever°为你锁心
5楼-- · 2019-08-17 01:07

50,000 objects seems a bit excessive for a dropdown menu item. Maybe you want to look at an alternative widget, like a table with paging...

查看更多
孤傲高冷的网名
6楼-- · 2019-08-17 01:14

You have a dropdown with 50000 items in it? That seems a trifle excessive. Perhaps a list view control? Also you can create the listview as a Virtual list view - in this mode it will only load the items as needed, the other items can be loaded if they would be scrolled into view. Since you are having so many items in the list view, I suggest you work on some kind of search control that the user can use to narrow down the list of items.

查看更多
登录 后发表回答