简体   繁体   中英

caching a collection of users

I have list of users i would like to cache for a certain amount of time but I have trouble with making connection to my model in getting users.

In my service layer:

public IEnumerable<Clients> GetClientVw(int sessionID)
            {
                var _key = GetVwCacheKey(sessionID);
                if (_cacheManager.Exists(_key, _cacheSettings.Group))
                {
                    return _cacheManager.Get<Clients>(_key, _cacheSettings.AbsoluteExpiration.AddHours(1.0).ToString());
                }
                var _result = GetClients(sessionID);
                if (_result != null)
                {
                    var _clientVw = _result.ClientsVw();
                    _cacheManager.Set<ClientsVw>(_key, _clientVw, _cacheSettings);
                    return _clientVw;
                }

                return null;
            }

This is what i have in my Model:

public class ClientsVw
    {
        public ClientsVw()
        {
            this.Clients = new HashSet<Clients>();
        }
        public IEnumerable<Clients> ClientsList { get; set; }
    }

    public class Clients
    {
        public int ID { get; set; }
        public string Name { get; set; }
        public string Email { get; set; }
    }

Errors: in my return _cacheManager.Get<Clients> it is telling me i am missing a cast because i cannot convert from Clients to IEnumerable

And in var _clientVw = _result.ClientVw(); it says that i don't have a definition for ClientVw()

FOR it is telling me i am missing a cast because i cannot convert from Clients to IEnumerable

you can try making it to list

  return _cacheManager.Get<Clients>(_key, _cacheSettings.AbsoluteExpiration.AddHours(1.0).ToString()).ToList();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM