c# - Saving data to cache and retrieving it -


i have been using following cache class

cache class

i have following in code, first sql statement

select id, ambitiousdescription [user].[ambitious_description] 

next part when read in list

var ambition = sqlcon.read().tolist(); 

i save cache, saves me doing multiple trips database.

cache.cacheextension.savetocache("ambition", ambition, new datetime(1)); 

at top of method check see if in cache shown here

 if (cache.cacheextension.isincache("ambition"))  {     var listambition = new selectlist(cache.cacheextension.getfromcache("ambition"), "1", "ambitiousdescription");  }  else  {    // otherwise database  } 

i red error under word getfromcache reads

enter image description here

i'm not 100% syntax retrieve cache if can i'd appreciate it.

update

after comments stephen decided create class called ambitiondetails shown here:

 public class ambitiondetails {     public int id { get; set; }      public string description { get; set; } } 

i populate doing following, first read results use linq populate list ambitiondetails

 // read data query multiple     var ambition = sqlcon.read().tolist();      var ambitiondetails = ambition.select(item => new ambitiondetails     {        id = item.id,        description = item.ambitiousdescription     }).tolist(); 

i save in cache shown here:

cache.cacheextension.savetocache("ambition", ambitiondetails, new datetime(1)); 

i try retrieve cache shown here here:

var listambition = new selectlist(cache.cacheextension.getfromcache<list<ambitiondetails>>("ambition"));              model.listambitious = new list<selectlistitem>();              model.listambitious.addrange(                     listambition.select(                         item => new selectlistitem { text = item.text, value = item.value.tostring() })); 

but null exception error on item => new selectlistitem, when put break point on

 var listambition; 

and expand see results text

"applicationname.shared.models.ambitiondetails" 

and value null

which i'm not sure what's going wrong here?


Comments

Popular posts from this blog

google chrome - Developer tools - How to inspect the elements which are added momentarily (by JQuery)? -

angularjs - Showing an empty as first option in select tag -

php - Cloud9 cloud IDE and CakePHP -