示例#1
0
        /// <summary>
        /// Initializes the SyncCache.
        /// </summary>
        public void Initialize()
        {
            try
            {
                CacheInitParams initParams = new CacheInitParams();
                initParams.Server      = _server;
                initParams.Port        = _port;
                initParams.LoadBalance = true;
                _syncCache             = Caching.NCache.InitializeCache(_cacheId, initParams, false);
                _updateCallback        = new CacheDataNotificationCallback(OnItemChangedCallback);
                _removedCallback       = new CacheDataNotificationCallback(OnItemRemovedCallback);
                _cacheClearCallback    = new CacheClearedCallback(OnCacheClear);
                _cacheStoppedCallback  = new CacheStoppedCallback(OnCacheStopped);
                _synEventListeners     = new ArrayList();

                if (_syncCache != null)
                {
                    _syncCache.ExceptionsEnabled = true;
                    _syncCache.CacheCleared     += _cacheClearCallback;
                    _syncCache.CacheStopped     += _cacheStoppedCallback;
                }
            }
            catch (Exception ex)
            {
                throw new Exception("Unable to initialize " + _cacheId + " while creating CacheSyncDependency", ex);
            }
        }
示例#2
0
        internal ClientConfiguration(string cacheId, CacheInitParams param)
        {
            _cacheId  = cacheId;
            initParam = (CacheInitParams)param.Clone();
            if (initParam != null)
            {
                if (initParam.ServerList != null && initParam.ServerList.Length > 0)
                {
                    foreach (CacheServerInfo serverInfo in initParam.ServerList)
                    {
                        serverInfo.ServerInfo.IsUserProvided = true;
                        AddServer(serverInfo.ServerInfo);
                    }

                    _loadServersFromConfigFile = false;
                }
                else if (initParam.Server != null)
                {
                    AddServer(new RemoteServer(initParam.Server, initParam.Port)
                    {
                        IsUserProvided = true
                    });
                }
            }
        }
示例#3
0
        public void StartTasks()
        {
            try
            {
                Thread[]        threads    = new Thread[_threadCount];
                CacheInitParams parameters = new CacheInitParams();

                _cache = Factory.InitializeCache(_cacheId, parameters);
                _cache.ExceptionsEnabled = true;

                string pid = System.Diagnostics.Process.GetCurrentProcess().Id.ToString();

                for (int threadIndex = 0; threadIndex < _threadCount; threadIndex++)
                {
                    StressThreadTask threadTask = new StressThreadTask(_cache, _totalLoopCount, _testCaseIterations, _testCaseIterationDelay, _getsPerIteration, _updatesPerIteration, _dataSize, _expiration, _threadCount, _reportingInterval, threadIndex, _outputProvider, _adapter);
                    _tasks.Add(threadTask);
                    threadTask.Start();
                }
                _adapter.Listen();
            }
            catch (Exception e)
            {
                throw e;
            }
        }
示例#4
0
        public void ClearCache(string cacheId, bool forceClear, bool webOnly)
        {
            Cache cache = null;

            try
            {
                CacheInitParams cacheParams = new CacheInitParams();


                cache = Web.Caching.NCache.InitializeCache(cacheId.ToLower(), cacheParams);


                if (!ForceClear)
                {
                    long count = cache.Count;
                    OutputProvider.WriteLine("");
                    OutputProvider.WriteLine("\"" + cacheId + "\" cache currently has " + count + " items. ");
                    OutputProvider.WriteLine("Do you really want to clear it (Y or N)? ");
                    ICollection <PSObject> response = this.InvokeCommand.InvokeScript("Read-Host");
                    string resp = string.Empty;
                    foreach (PSObject r in response)
                    {
                        resp = r.ToString();
                    }
                    if (resp != "Y" && resp != "y")
                    {
                        OutputProvider.WriteLine("");
                        OutputProvider.WriteLine("Cache not cleared.");
                        return;
                    }
                }

                cache.Clear();

                OutputProvider.WriteLine("");



                OutputProvider.WriteLine("Cache cleared.");
            }
            catch (Exception e)
            {
                OutputProvider.WriteLine("Error: " + e.Message);
                OutputProvider.WriteErrorLine(e.ToString());
            }
            finally
            {
                if (cache != null)
                {
                    cache.Dispose();
                }
            }
        }
示例#5
0
        private static CacheInitParams GetInitParams(ref ToolArgs toolArgs)
        {
            CacheInitParams initParams = new CacheInitParams();
            string          ip         = "";

            if (string.IsNullOrEmpty(toolArgs.Server))
            {
                return(initParams);
            }
            else
            {
                int port = toolArgs.Port != 0 ? toolArgs.Port : 9800;
                CacheServerInfo[] cacheServerInfos = new CacheServerInfo[1];
                cacheServerInfos[0]   = new CacheServerInfo(ip, port);
                initParams.ServerList = cacheServerInfos;
                return(initParams);
            }
        }
示例#6
0
 public ClientConfiguration(string cacheId)
 {
     _cacheId  = cacheId;
     initParam = null;
 }
示例#7
0
 public static Cache InitializeInternally(string cacheName, CacheInitParams iparams,
                                          bool isPessim)
 {
     return(Caching.NCache.InitializeCache(cacheName, iparams, isPessim));
 }
示例#8
0
 /// <summary>
 /// Configures NCache to be used as a second level cache for entity framework.
 /// </summary>
 /// <param name="cacheId">Cache id that will be used to store result sets.</param>
 /// <param name="databaseType">Database type that will be used when creating database dependencies.</param>
 /// <param name="initParams">Additional parameters used to initialize NCache.</param>
 public static void Configure(string cacheId, DependencyType databaseType, /*DbContext context, */ CacheInitParams initParams)
 {
     _initParams = initParams;
     Configure(cacheId, databaseType);
 }