Can I use the static cache caching method in NET MVC controller?

I understand that there have been several posts about where to add check / update cache and separation of problems between the controller, model and caching code.

There are two great examples that I tried to work with, but am new to MVC. I wonder which one is the cleanest and best suited for the MVC methodology? I know that you need to consider DI and unit testing.

Example 1 (Assistant with a delegate)

... in the controller

var myObject = CacheDataHelper.Get(thisID, () =>
WebServiceServiceWrapper.GetMyObjectBythisID(thisID));

Example 2 (checking the cache in the model class) in the controller

var myObject =   WebServiceServiceWrapper.GetMyObjectBythisID(thisID));

then in the model class ..............

if (!CacheDataHelper.Get(cachekey, out myObject)) {

//do some repository processing

// Add obect to cache CacheDataHelper.Add(myObject, cachekey);

}

--, , . , , .

.

- , MVC. - , - , , ?

, . , , , ?

+3
2

, 1 - , . , , , . , , .., .

. DI, -, ..

+2

, , . -. . , CacheHelper (), . .

DI , , , , null. , factory, , . , , .

- - Cache. , .

+1

Source: https://habr.com/ru/post/1749013/


All Articles