/// <summary>
 /// 初始化缓存
 /// </summary>
 static TransactionScope()
 {
     if (_DatabaseChache == null)
     {
         _DatabaseChache = CacheFactory.GetCacheManager("DBTransactionCacheManager");
     }
 }
Exemple #2
0
 private ResourceCache()
 {
     replacemntStringCache  = CacheFactory.GetCacheManager(REPLACEMENT_STRING_CACHE);
     logMessageCache        = CacheFactory.GetCacheManager(LOG_MESSAGES_CACHE);
     errorMessageCache      = CacheFactory.GetCacheManager(ERROR_MESSAGES_CACHE);
     landingPageCache       = CacheFactory.GetCacheManager(LANDING_PAGE_CACHE);
     resourceStringProvider = new MessageStringProvider();
     LoadCache();
     if (Directory.Exists(resourceStringProvider.Path))
     {
         _xmlFileWatcher        = new FileSystemWatcher();
         _xmlFileWatcher.Path   = resourceStringProvider.Path;
         _xmlFileWatcher.Filter = "*.xml";
         _xmlFileWatcher.IncludeSubdirectories = true;
         _xmlFileWatcher.EnableRaisingEvents   = true;
         _xmlFileWatcher.Changed += new System.IO.FileSystemEventHandler(xmlFileWatcher_Changed);
     }
     else if (Directory.Exists(resourceStringProvider.SEMPath))
     {
         _xmlFileWatcher        = new FileSystemWatcher();
         _xmlFileWatcher.Path   = resourceStringProvider.SEMPath;
         _xmlFileWatcher.Filter = "*.xml";
         _xmlFileWatcher.IncludeSubdirectories = true;
         _xmlFileWatcher.EnableRaisingEvents   = true;
         _xmlFileWatcher.Changed += new System.IO.FileSystemEventHandler(xmlFileWatcher_Changed);
     }
 }
Exemple #3
0
        /// <summary>
        /// 把值放到缓存里,并指定依赖文件的路径
        /// </summary>
        /// <param name="key">键</param>
        /// <param name="value">值</param>
        /// <param name="path">依赖文件的路径</param>
        public static void SetCacheItem(string key, object value, string path)
        {
            ICacheManager  cache = CacheFactory.GetCacheManager("CacheManager");
            FileDependency fd    = new FileDependency(path);

            cache.Add(key, value, CacheItemPriority.Normal, null, new ICacheItemExpiration[] { fd });
        }
Exemple #4
0
        public Stream createUserAsJSON(User user)
        {
            // retrieve the users cache manager
            if (usersCacheManager == null)
            {
                usersCacheManager = CacheFactory.GetCacheManager(USERS_CACHE);
            }

            // check a usersCacheManager is configured
            if (usersCacheManager == null)
            {
                // usersCacheManager not configured
                //logger.error("cache manager not configured");

                // build an error message
                Error error = new Error();
                error.code        = System.Net.HttpStatusCode.InternalServerError.ToString();
                error.description = "cache manager not configured";

                // return a server error
                return(serializeErrorToJSONStream(error, System.Net.HttpStatusCode.InternalServerError));
            }

            // populate the id with the local id
            user.id = "uid=" + user.externalId + ",dc=hackerypokery,dc=com";

            // store the user in the cache
            usersCacheManager.Add(user.id, user);

            // return the user with the created status
            return(serializeUserToJSONStream(user, System.Net.HttpStatusCode.Created));
        }
        /// <summary>
        /// 添加缓存项,该项在指定的时间过期
        /// </summary>
        public void Add(string cacheManagerName, string key, object obj, DateTime absoluteTime)
        {
            Microsoft.Practices.EnterpriseLibrary.Caching.ICacheManager
                cacheManager = CacheFactory.GetCacheManager(cacheManagerName);

            cacheManager.Add(key, obj, CacheItemPriority.Normal, null, new AbsoluteTime(absoluteTime));
        }
 public Strategy2020Presenter(IStrategy2020ReportView view)
 {
     this.view       = view;
     this.filterData = new Strategy2020FilterData();
     filterNames     = InitializeFilterNames();
     this.cache      = CacheFactory.GetCacheManager();
 }
Exemple #7
0
 public Strategy2020ContentBuilder()
 {
     cache = CacheFactory.GetCacheManager();
     data  = new Strategy2020Data();
     InitializeTypes();
     content = new Strategy2020Content();
 }
Exemple #8
0
        private void MainWindow_Loaded(object sender, RoutedEventArgs e)
        {
            _positionCache = CacheFactory <PositionKey, Position> .GetCacheManager();

            viewModel        = new ViewModel();
            this.DataContext = viewModel;
        }
        public void Refresh(string removedKey, object expiredValue, CacheItemRemovedReason removalReason)
        {
            CacheManager channelListCache = CacheFactory.GetCacheManager();

            channelListCache.Add(removedKey, GetChannels(), CacheItemPriority.Normal, null
                                 , null /*new AbsoluteTime(DateTime.Now.AddMilliseconds(Settings.Default.PlaylistRefreshInterval/2))*/);
        }
Exemple #10
0
    public object Invoke(object instance, object[] inputs, out object[] outputs)
    {
        object result = null;

        ///TODO: You will have more object in the input if you have more ///parameters in your method

        string angle = inputs[1].ToString();

        ///TODO: create a unique key from the inputs
        string key = angle;

        string provider = System.Configuration.ConfigurationManager.AppSettings["CacheProviderName"];

        ///Important Provider will be DiskCache or MemoryCache for the moment
        provider = ”DiskCache”;
        ///TODO: call enterprise library cache manager, You can have your own
        /// custom cache like Hashtable

        ICacheManager manager = CacheFactory.GetCacheManager(provider);

        if (manager.Contains(key))
        {
            result = (MyCompositeClass)manager[key];
        }
        else
        {
            result = (MyCompositeClass)_innerOperationInvoker.Invoke(instance, inputs, out outputs);
            manager.Add(key, result);
        }
        return(result);
    }
Exemple #11
0
        public UserService()
        {
            // create a test user
            User user = new User();

            user.userName    = "******";
            user.externalId  = "mcrooke";
            user.displayName = "Mr Matt Crooke";

            // set the user names
            user.name            = new Name();
            user.name.givenName  = "Matt";
            user.name.familyName = "Crooke";
            user.name.formatted  = "Mr Matt Crooke";

            // set the user emails
            PluralAttribute email = new PluralAttribute();

            email.primary = true;
            email.value   = "*****@*****.**";
            PluralAttribute[] emails = new PluralAttribute[] { email };
            user.emails = emails;

            // retrieve the users cache manager
            if (usersCacheManager == null)
            {
                usersCacheManager = CacheFactory.GetCacheManager(USERS_CACHE);
            }

            // populate the id with the local id
            user.id = "uid=" + user.externalId + ",dc=hackerypokery,dc=com";

            // store the user in the cache
            usersCacheManager.Add(user.id, user);
        }
        /// <summary>
        /// Adds the specified cache manager name.
        /// </summary>
        /// <param name="cacheManagerName">Name of the cache manager.</param>
        /// <param name="key">The key.</param>
        /// <param name="obj">The obj.</param>
        public void Add(string cacheManagerName, string key, Object obj)
        {
            Microsoft.Practices.EnterpriseLibrary.Caching.ICacheManager
                cacheManager = CacheFactory.GetCacheManager(cacheManagerName);

            cacheManager.Add(key, obj);
        }
Exemple #13
0
        public MainWindow()
        {
            InitializeComponent();

            _primitivesCache = CacheFactory.GetCacheManager();
            _memoryCache     = MemoryCache.Default;
        }
        //private SqlDependencyExpiration GetSqlDependencyExpiration(string sqlDependencyProcName, Dictionary<string, object> parameters)
        //{
        //    SqlDependencyExpiration expiration = new SqlDependencyExpiration(sqlDependencyProcName, parameters);
        //    //expiration.Expired += delegate
        //    //{
        //    //    MessageBox.Show("Cache has expired!");
        //    //};
        //    return expiration;
        //}

        /// <summary>
        /// Adds the specified cache manager name.
        /// </summary>
        /// <param name="cacheManagerName">Name of the cache manager.</param>
        /// <param name="key">The key.</param>
        /// <param name="obj">The obj.</param>
        /// <param name="file">The file.</param>
        public void Add(string cacheManagerName, string key, Object obj, string file)
        {
            Microsoft.Practices.EnterpriseLibrary.Caching.ICacheManager
                cacheManager = CacheFactory.GetCacheManager(cacheManagerName);

            cacheManager.Add(key, obj, CacheItemPriority.Normal, null, new FileDependency(file));
        }
        public void Add(string cacheManagerName, string key, object obj, params SqlDependencyExpiration[] expirations)
        {
            Microsoft.Practices.EnterpriseLibrary.Caching.ICacheManager
                cacheManager = CacheFactory.GetCacheManager(cacheManagerName);

            cacheManager.Add(key, obj, CacheItemPriority.Normal, null, expirations);
        }
Exemple #16
0
 /// <summary>
 /// 返回指定Key的对象
 /// </summary>
 /// <param name="objId">对象的关键字</param>
 /// <returns>对象</returns>
 public virtual object GetObject(string objId)
 {
     if (objId == null || objId.Length == 0)
     {
         return(null);
     }
     return(CacheFactory.GetCacheManager().GetData(objId));
 }
        public MainWindow()
        {
            InitializeComponent();
            DataContext    = this;
            _positionCache = CacheFactory <PositionKey, Position> .GetCacheManager();

            MyListViewBinding = new ObservableCollection <string>();
        }
        /// <summary>
        /// Adds the specified cache manager name.
        /// </summary>
        /// <param name="cacheManagerName">Name of the cache manager.</param>
        /// <param name="key">The key.</param>
        /// <param name="obj">The obj.</param>
        /// <param name="duration">滑动过期时间,以秒为单位</param>
        public void Add(string cacheManagerName, string key, Object obj, int slidingExpirationSeconds)
        {
            Microsoft.Practices.EnterpriseLibrary.Caching.ICacheManager
                cacheManager = CacheFactory.GetCacheManager(cacheManagerName);

            cacheManager.Add(
                key, obj, CacheItemPriority.Normal, null, new SlidingTime(TimeSpan.FromSeconds(slidingExpirationSeconds)));
        }
        /// <summary>
        /// Gets the data.
        /// </summary>
        /// <param name="cacheManagerName">Name of the cache manager.</param>
        /// <param name="key">The key.</param>
        /// <returns></returns>
        public T GetData <T>(string cacheManagerName, string key)
        {
            Microsoft.Practices.EnterpriseLibrary.Caching.ICacheManager
                cacheManager = CacheFactory.GetCacheManager(cacheManagerName);
            T   obj          = (T)cacheManager.GetData(key);

            return(obj);
        }
        /// <summary>
        /// Adds the specified cache manager name and never expired.
        /// </summary>
        /// <param name="cacheManagerName">Name of the cache manager.</param>
        /// <param name="key">The key.</param>
        /// <param name="obj">The obj.</param>
        public void AddNeverExpired(string cacheManagerName, string key, Object obj)
        {
            Microsoft.Practices.EnterpriseLibrary.Caching.ICacheManager
                cacheManager = CacheFactory.GetCacheManager(cacheManagerName);

            cacheManager.Add(
                key, obj, CacheItemPriority.Normal, null, new NeverExpired());
        }
Exemple #21
0
 protected override void InitializeCache()
 {
     if (DisabledDueToTesting)
     {
         return;
     }
     _cacheManager = CacheFactory.GetCacheManager("WebCacheManager");
 }
Exemple #22
0
 /// <summary>
 /// 自定义刷新操作
 /// </summary>
 /// <param name="removedKey">移除的键</param>
 /// <param name="expiredValue">过期的值</param>
 /// <param name="removalReason">移除理由</param>
 void ICacheItemRefreshAction.Refresh(string removedKey, object expiredValue, CacheItemRemovedReason removalReason)
 {
     if (removalReason == CacheItemRemovedReason.Expired)
     {
         ICacheManager cache = CacheFactory.GetCacheManager();
         cache.Add(removedKey, expiredValue);
     }
 }
 public CachingService()
 {
     _primitivesCache = CacheFactory.GetCacheManager();
     _eventAggregator.GetEvent <ProjectPreCloseEvent>().Subscribe((e) =>
     {
         _primitivesCache.Flush();
     });
 }
        public void AddProductToELCacheManager()
        {
            ICacheManager cacheManager     = CacheFactory.GetCacheManager();
            var           assignedProducts = Category.AssignedProducts(_apiUrl, _sessionId, new object[] { "47" });

            cacheManager.Add("test", assignedProducts);
            Assert.IsNotNull(assignedProducts, "Nessun prodoto trovato");
        }
        private CacheManager GetCacheManagerInstance()
        {
            CachingStoreProviderData cachingStoreProviderData = GetCacheStorageProviderData();

            string cacheManagerInstance = (cachingStoreProviderData.CacheManager.Length > 0) ? cachingStoreProviderData.CacheManager : null;

            return(CacheFactory.GetCacheManager(cacheManagerInstance));
        }
Exemple #26
0
        public void RunRandomThreadsInDatabase()
        {
//            Console.WriteLine("\n\n\n********");
//            Console.WriteLine("*** RunRandomThreadsInDatabase");
//            Console.WriteLine("********\n\n\n");
            currentCacheManager = CacheFactory.GetCacheManager("InDatabasePerformanceTest");
            RunTest(new ThreadStart(RandomWorkerMethod));
        }
Exemple #27
0
        /// <summary>
        /// 加入当前对象到缓存中
        /// </summary>
        /// <param name="objId">对象的键值</param>
        /// <param name="o">缓存的对象</param>
        public virtual void AddObject(string objId, object o, DateTime dtTimeout)
        {
            if (objId == null || objId.Length == 0 || o == null)
            {
                return;
            }

            CacheFactory.GetCacheManager().Add(objId, o, CacheItemPriority.High, null, new AbsoluteTime(dtTimeout));
        }
Exemple #28
0
        public void RunThreadsInMemory()
        {
//            Console.WriteLine("\n\n\n********");
//            Console.WriteLine("*** RunThreadsInMemory");
//            Console.WriteLine("********\n\n\n");
            currentCacheManager = CacheFactory.GetCacheManager("InMemoryPerformanceTest");

            RunTest(new ThreadStart(WorkerMethod));
        }
Exemple #29
0
        /// <summary>
        /// 文件依赖
        /// </summary>
        /// <param name="objId"></param>
        /// <param name="o"></param>
        /// <param name="files"></param>
        public void AddObjectWithFileChange(string objId, object o, string files)
        {
            if (objId == null || objId.Length == 0 || o == null)
            {
                return;
            }
            FileDependency _fileDep = new FileDependency(files);

            CacheFactory.GetCacheManager().Add(objId, o, CacheItemPriority.High, null, _fileDep);
        }
Exemple #30
0
    /// <summary>
    /// add item into cache
    /// </summary>
    /// <param name="cacheKey">key of cache item</param>
    /// <param name="value">new item</param>
    public static void SetCache(string cacheKey, object value)
    {
        ICacheManager cacheMgr = CacheFactory.GetCacheManager();

        if (cacheMgr.Contains(cacheKey))
        {
            cacheMgr.Remove(cacheKey);
        }
        cacheMgr.Add(cacheKey, value);
    }