Пример #1
0
        protected IQueryable <GeoDataEntry> Search(string searchTerm, BoundingBox boundingBox, int maxResults)
        {
            lock (Entries)
            {
                //always want to query at least DataProviderMinResults # of entries  so that
                //Ranking logic is (most) accurately applied
                maxResults = Math.Max(maxResults, DataProviderMinResults);

                //remove entry if it already exists and is expired
                var             newKey      = new ServiceCacheKey(StringComparer, boundingBox, searchTerm, maxResults);
                ServiceCacheKey existingKey = Entries.ContainsKey(newKey) ? Entries.Keys.Single(k => k.Equals(newKey)) : null;

                if (existingKey != null && IsFlushable(existingKey))
                {
                    Entries.Remove(existingKey);
                    existingKey = null;
                }


                //if this set of args hasn't been queried before, or
                //if it has but for a lower number of maxResults, refresh cache for this key
                if (existingKey == null || existingKey.MaxResults < maxResults)
                {
                    if (boundingBox != null)
                    {
                        Entries[newKey] = DataProvider.SearchNear(searchTerm, boundingBox, maxResults);
                    }
                    else
                    {
                        Entries[newKey] = DataProvider.Search(searchTerm.Trim(), maxResults);
                    }
                }
                return(Entries[newKey]);
            }
        }
 private void AddCacheKey(ILEmitResolverBuilderContext argument, ServiceCacheKey key)
 {
     // new ServiceCacheKey(typeof(key.Type), key.Slot)
     argument.Generator.Emit(OpCodes.Ldtoken, key.Type);
     argument.Generator.Emit(OpCodes.Call, GetTypeFromHandleMethod);
     argument.Generator.Emit(OpCodes.Ldc_I4, key.Slot);
     argument.Generator.Emit(OpCodes.Newobj, CacheKeyCtor);
 }
Пример #3
0
 /// <summary>
 /// returns true if a cache entry has expired
 /// </summary>
 /// <returns></returns>
 protected bool IsFlushable(ServiceCacheKey key)
 {
     return(DateTime.Now - key.CreatedTime > CacheDuration);
 }