using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Foresight.Cache;
using Foresight.Service.Cache;
using Foresight.Fleet.Services.SystemOption;
using Foresight.Fleet.Services;

namespace IronIntel.Contractor
{
    public static class CacheManager
    {
        private static string CacheRegion
        {
            get { return "FLEET_" + SystemParams.CompanyID.ToUpper(); }
        }

        public static void Remove(string key)
        {
            var client = FleetServiceClientHelper.CreateClient<SystemUtil>();
            try
            {
                client.RemoveCache(CacheRegion, key);
            }
            catch
            { }
        }

        public static void SetValue(string key, byte[] buffer, TimeSpan expire)
        {
            var client = FleetServiceClientHelper.CreateClient<SystemUtil>();
            try
            {
                client.SetCache(CacheRegion, key, buffer, (int)expire.TotalSeconds);
            }
            catch
            { }
        }

        public static byte[] GetValue(string key)
        {

            try
            {
                var client = FleetServiceClientHelper.CreateClient<SystemUtil>();
                return client.GetCache(CacheRegion, key);
            }
            catch
            {
                return null;
            }

        }
    }
}
