Quantcast
Channel: .NET Framework Class Libraries forum
Viewing all articles
Browse latest Browse all 8156

MemoryCache with Attribute

$
0
0

I need to cache the results of method calls by time. I saw this MemoryCache class, but how can I create an Attribute like Asp.net MVC Cache?

To do that, I think I need to intercept the calling method, but how can I do that?

public class ProfileSelectionService : IProfileSelectionService
    {
        private readonly IWmbWebService webService;
        private readonly ISessionManager sessionManager;

        public ProfileSelectionService(IWmbWebService webService, ISessionManager sessionManager)
        {
            this.webService = webService;
            this.sessionManager = sessionManager;
        }

        public IEnumerable<StreamServer> GetServers()
        {
            return sessionManager.IsUserLogged() ? webService.GetServers() : Enumerable.Empty<StreamServer>();
        }

        public IEnumerable<Profile> GetProfiles()
        {
            return sessionManager.IsUserLogged() ? webService.GetProfiles() : Enumerable.Empty<Profile>();
        }
    }

For example, the above class calls a WebService, but I don't need to call it everytime and I don't want write cache logic to this class either, because it will break the Single Responsability Principle among other things.

If it helps, I'm using an IoC container to resolve dependencies. I'm using Unity


Take a look at WPF FlashMessage
About.me



Viewing all articles
Browse latest Browse all 8156

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>