public static void Register(string globalCacheName, string name, ICacheDictionary cache)
 {
     try
     {
         InsertCacheRegistryInfo(new CacheRegistryInfo()
         {
             //ApplicationCode = "MAESTRO",
             CacheId = name,
             //GlobalCacheName = name,
             HostName = Environment.MachineName
         });
     }
     catch (Exception e)
     {
         logger.Fatal(e, "'" + name + "' cache nesnesi register edilemedi.RegisterCache");
     }
     lock (registry)
     {
         try
         {
             if (!registry.ContainsKey(name))
             {
                 registry.Add(name, cache);
             }
             logger.Info("'" + name + "' cache nesnesi register edildi.");
         }
         catch (Exception e)
         {
             logger.Fatal(e, "'" + name + "' cache nesnesi register edilemedi.");
         }
     }
 }
Ejemplo n.º 2
0
 public CommandsHandler(ICacheDictionary <string, Dictionary <string, string> > cacheDictionary, Command[] commands)
 {
     this.cacheDictionary = cacheDictionary;
     foreach (var command in commands)
     {
         allCommands.Add(command.Name, command);
     }
 }
        public static CacheInfo GetCacheInfo(string cacheId)
        {
            ICacheDictionary cache = null;

            if (CacheRegistry.registry.TryGetValue(cacheId, out cache))
            {
                CacheInfo ci = new CacheInfo();
                //ci.GlobalCacheName = cache.GlobalCacheName;
                ci.CacheId        = cache.CacheId;
                ci.Count          = cache.Count;
                ci.ReloadDuration = 1000;
                ci.ReloadTime     = DateTime.Now;
                return(ci);
            }
            return(null);
        }
Ejemplo n.º 4
0
        public EchoBot(IDbContext <TTimeTableEvent, TEvent, TUser> db,
                       ICacheDictionary <string, Dictionary <string, string> > cacheDictionary,
                       ITurnContext <IMessageActivity> turnContext)
        {
            this.db = db;
            this.cacheDictionary = cacheDictionary;

            commands = new Command[]
            {
                new CreateTimeTableCommand <TTimeTableEvent, TEvent, TUser>(db, cacheDictionary),
                new ShowTimeTableCommand <TTimeTableEvent, TEvent, TUser>(db),
                new RemoveTimeTableCommand <TTimeTableEvent, TEvent, TUser>(db, cacheDictionary),
                new GetTopVisitUsersCommand <TTimeTableEvent, TEvent, TUser>(db),
                new NotificatorCommand <TTimeTableEvent, TEvent, TUser>(db, turnContext),
                new ShowAllNotificationsCommand <TTimeTableEvent, TEvent, TUser>(db)
            };
        }
Ejemplo n.º 5
0
                public Cache(Func <T, R> function, Func <IMemoizationCacheEntryMetrics, TMetric> ranker, int maxCapacity, bool descending, double ageThreshold, IEqualityComparer <T> comparer, bool cacheError, IStopwatchFactory stopwatchFactory)
                {
                    _function = args =>
                    {
                        var invokeDuration = default(TimeSpan);
#if DEBUG
                        _invocationCount++;
#endif
                        Trim();

                        var res = default(IMetricsCacheEntry <T, R>);
                        try
                        {
                            var swInvokeStart = _stopwatch.ElapsedTicks;

                            var value = function(args);

                            invokeDuration = new TimeSpan(_stopwatch.ElapsedTicks - swInvokeStart);

                            res = new MetricsValueCacheEntry <T, R>(args, value);
                        }
                        catch (Exception ex) when(_cacheError)
                        {
                            res = new MetricsErrorCacheEntry <T, R>(args, ex);
                        }

                        res.CreationTime   = new TimeSpan(_stopwatch.ElapsedTicks);
                        res.InvokeDuration = invokeDuration;

                        return(res);
                    };

                    _cache     = new CacheDictionary <T, IMetricsCacheEntry <T, R> >(comparer);
                    _stopwatch = stopwatchFactory.StartNew();

                    //
                    // Exclude newest items which have statically irrelevant data, so they get a chance to become relevant.
                    //
                    var candidates = _cache.Values.OrderBy(e => _stopwatch.ElapsedTicks - e.CreationTime.Ticks).Take(Math.Max(1, (int)(maxCapacity * ageThreshold)));
                    _ranker = descending ? candidates.OrderByDescending(e => ranker(e)) : candidates.OrderBy(e => ranker(e));

                    _maxCapacity = maxCapacity;
                    _cacheError  = cacheError;
                }
 public PlatformClient(Uri plusBaseUrl, Uri talkBaseUrl,
     System.Net.CookieContainer cookie, IApiAccessor accessor,
     ICacheDictionary<string, ProfileCache, ProfileData> profileCacheStorage,
     CacheDictionary<string, ActivityCache, ActivityData> activityCacheStorage)
 {
     var handler = new System.Net.Http.HttpClientHandler() { CookieContainer = cookie };
     Cookies = cookie;
     ServiceApi = accessor;
     PlusBaseUrl = plusBaseUrl;
     TalkBaseUrl = talkBaseUrl;
     NormalHttpClient = new System.Net.Http.HttpClient(handler);
     NormalHttpClient.DefaultRequestHeaders.Add("user-agent", ApiAccessorUtility.UserAgent);
     StreamHttpClient = new System.Net.Http.HttpClient(handler);
     StreamHttpClient.Timeout = TimeSpan.FromMinutes(15);
     StreamHttpClient.DefaultRequestHeaders.Add("user-agent", ApiAccessorUtility.UserAgent);
     People = new PeopleContainer(this, profileCacheStorage);
     Activity = new ActivityContainer(this, activityCacheStorage);
     Notification = new NotificationContainer(this);
 }
Ejemplo n.º 7
0
        public UnboundedMemoizationCacheWithExceptionBase(Func <T, R> function, ICacheDictionary <T, IValueOrError <R> > cache)
        {
            _function = args =>
            {
#pragma warning disable IDE0079 // Remove unnecessary suppression
#pragma warning disable CA1031  // Do not catch general exception types (by design)
                try
                {
                    return(ValueOrError.CreateValue <R>(function(args)));
                }
                catch (Exception ex)
                {
                    return(ValueOrError.CreateError <R>(ex));
                }
#pragma warning restore CA1031
#pragma warning restore IDE0079
            };

            _cache = cache;
        }
                public Cache(Func <T, R> function, int maxCapacity, IEqualityComparer <T> comparer, bool cacheError)
                {
                    _function = args =>
                    {
#if DEBUG
                        var invokeDuration = default(TimeSpan);
                        _invocationCount++;
#endif
                        Trim();

                        var res = default(ILruCacheEntry <T, R>);
                        try
                        {
#if DEBUG
                            var swInvoke = Stopwatch.StartNew();
#endif
                            var value = function(args);
#if DEBUG
                            invokeDuration = swInvoke.Elapsed;
#endif
                            res = new LruValueCacheEntry <T, R>(args, value);
                        }
                        catch (Exception ex) when(_cacheError)
                        {
                            res = new LruErrorCacheEntry <T, R>(args, ex);
                        }
#if DEBUG
                        res.GetMetrics().InvokeDuration = invokeDuration;
#endif
                        return(res);
                    };

                    _cache       = new CacheDictionary <T, ILruCacheEntry <T, R> >(comparer);
                    _maxCapacity = maxCapacity;
                    _cacheError  = cacheError;
                }
Ejemplo n.º 9
0
		public void Update(ICacheDictionary newVersionOfCacheDictionary)
		{
			throw new NotImplementedException();
		}
Ejemplo n.º 10
0
 public void Update(ICacheDictionary newVersionOfCacheDictionary)
 {
     throw new NotImplementedException();
 }
Ejemplo n.º 11
0
 public UnboundedMemoizationCacheBase(Func <T, R> function, ICacheDictionary <T, R> cache)
 {
     _function = function;
     _cache    = cache;
 }
 public RemoveTimeTableCommand(IDbContext <TTimeTableEvent, TEvent, TUser> context,
                               ICacheDictionary <string, Dictionary <string, string> > cacheDictionary) : base(@"/tt remove")
 {
     db = context;
     this.cacheDictionary = cacheDictionary;
 }