Why does ConcurrentDictionary.GetOrAdd(key, valueFactory) allow the valueFactory to be invoked twice?

You could use a dictionary that is typed like this: ConcurrentDictionary<TKey, Lazy<TValue>>, and then the your value factory would return a Lazy<TValue> object that has been initialized with LazyThreadSafetyMode.ExecutionAndPublication, which is the default option used by Lazy<TValue> if you don’t specify it. By specifying the LazyThreadSafetyMode.ExecutionAndPublication you are telling Lazy only one thread may initialize … Read more

HttpContext.Cache Expiration

You can specify it in the 4th parameter of Cache.Add(): public Object Add( string key, Object value, CacheDependency dependencies, DateTime absoluteExpiration, // After this DateTime, it will be removed from the cache TimeSpan slidingExpiration, CacheItemPriority priority, CacheItemRemovedCallback onRemoveCallback ) Edit: If you access the cache via the indexer (i.e. Cache[“Key”]), the method that is called … Read more

Manually clear ASP.NET server cache for a single application/web site?

Use the following to remove all objects from the cache IDictionaryEnumerator enumerator = HttpContext.Current.Cache.GetEnumerator(); while (enumerator.MoveNext()) { HttpContext.Current.Cache.Remove((string)enumerator.Key); } Also, it is a bit of a sledgehammer option but you can restart the entire application as follows: System.Web.HttpRuntime.UnloadAppDomain();

MySQL query caching: limited to a maximum cache size of 128 MB?

The warning issued by mysqltuner.py is actually relevant even if your cache has no risk of being swapped. It is well-explained in the following: http://blogs.oracle.com/dlutz/entry/mysql_query_cache_sizing Basically MySQL spends more time grooming the cache the bigger the cache is and since the cache is very volatile under even moderate write loads (queries gets cleared often), putting … Read more

Caching and gzip compression by htaccess

# 480 weeks <FilesMatch “\.(ico|pdf|flv|jpg|jpeg|png|gif|js|css|swf)$”> Header set Cache-Control “max-age=290304000, public” </FilesMatch> # 2 DAYS <FilesMatch “\.(xml|txt)$”> Header set Cache-Control “max-age=172800, public, must-revalidate” </FilesMatch> # 2 HOURS <FilesMatch “\.(html|htm)$”> Header set Cache-Control “max-age=7200, must-revalidate” </FilesMatch> <ifModule mod_gzip.c> mod_gzip_on Yes mod_gzip_dechunk Yes mod_gzip_item_include file \.(html?|txt|css|js|php|pl)$ mod_gzip_item_include handler ^cgi-script$ mod_gzip_item_include mime ^text/.* mod_gzip_item_include mime ^application/x-javascript.* mod_gzip_item_exclude mime ^image/.* … Read more

How to cache database tables to prevent many database queries in Asp.net C# mvc

You could use the built-in MemoryCache to store entire resultsets you have retrieved from the database. A typical pattern: MyModel model = MemoryCache.Default[“my_model_key”] as MyModel; if (model == null) { model = GetModelFromDatabase(); MemoryCache.Default[“my_model_key”] = model; } // you could use the model here

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)