53 Commits
Author SHA1 Message Date
Dmitry Kalyanov d933418d23 Fix data race in System.Web.Caching by using appropriate lock level
System.Web.Caching.CacheItemLRU.this[string].get modifies LRU list so it
must be called under write lock. Cache.GetKeyLastChange violates this
constraint by acquiring only a read lock.

Fixes #12218
2018-12-31 15:36:36 -05:00
Marek Habersack 0eff07d0fc [asp.net] Better handling of item timeout reset in the in-proc session handler
The in-proc session handler no longer removes and re-inserts an item in order to
update its timeout. It is now done using Cache.SetItemTimeout which, in turn, checks
whether the item being updated is already a timed one and, if yes, calls CacheItemPriorityQueue's
Update method for that item. Should the update fail or the item is not yet timed, the item is
enqueued to the priority queue in the regular fashion.

CacheItem got a new member, PriorityQueueIndex to mark its position in the queue's heap for faster
lookup and manipulation.

The CacheItemPriorityQueue.BubbleDown method was rewritten to properly swap items in the heap.
2011-04-11 14:48:13 +02:00
Marek Habersack 1a9d2e5148 [asp.net] Don't throw NREX when a cache item to be removed is null 2011-01-20 23:38:27 +01:00
Marek Habersack 4b785e19d7 [asp.net] Disabled array clearing on heap resize in CacheItemPriorityQueue as it causes NREX to be thrown with > 8192 items in the queue.
- Rewrote the CacheItem priority queue test generator to generate better code.
- CacheItem in System.Web doesn't have the unused Guid field now (the field is used only for tests)
- Added a huge sequence to CacheItem priority queue tests (10k entries)
2010-11-19 02:30:16 +01:00
Marek Habersack 3b8cd7bbce [asp.net] New version of code to purge underused entries from the cache.
This version uses an LRU cache to hold the cache items. Priority is not taken into account
when removing the underused entries (with the exception of the CacheItemPriority.NotRemovable
- items with this priority are never purged), they are treated equally.
A separate thread is not used to perform purging, instead the collection happens in the current
requests's thread.
Minor improvements to cache item enumerator and to the CheckDependencies method.
2010-11-16 04:03:26 +01:00
Marek Habersack bd2ff0ebde [asp.net] Remove unnecessary try/catch block from the old entries expiration code. 2010-11-15 22:57:11 +01:00
Marek Habersack 8940995fc8 [asp.net] Cache + SessionInProcHandler memory usage improvements
* Cache.cs: cache removes old/least recently used items when the item count exceeds 15000. Items
  are removed until they reach the count of 10000.
* SessionInProcHandler.cs: replaced ReaderWriterLock with ReaderWriterLockSlim and added a Dispose
  method to the InProcSessionItem type which disposes the associated lock and other resources.
2010-11-13 04:14:33 +01:00
Marek Habersack c4b5cb7a86 [asp.net] Expire items must always check if the dequeued item is not null before using it. 2010-11-05 00:30:10 +01:00
Marek Habersack b91056243b [asp.net] Remove lock recursion in Cache.ExpireItems 2010-09-28 22:34:34 +02:00
Marek Habersack ae23776616 [asp.net] Get rid of a possible (although unlikely) race condition when acquiring locks
The patch removes a small race condition where a boolean flag is set after acquiring a lock to
indicate to code executing in the finally {} block that it should release the lock. The boolean
variable is now removed and the lock is released unconditionally. It carries a potential to
throw an exception when the lock is not held, but it's better than to fail to release it and
lead the application to a deadlock.
2010-09-28 13:29:21 +02:00
Marek Habersack 73c3bfba56 2010-02-03 Marek Habersack <[email protected]>
* AssemblyInfo.cs: added back InternalsVisibleTo for the test
        assembly - it's needed to access CacheItemPriorityQueue

2010-02-03  Marek Habersack  <[email protected]>

        * OutputCache.cs: DefaultProviderName checks if there was any
        provider configured and, if not, returns a built-in provider's
        name.

        * SqlCacheDependencyAdmin.cs: added

        * OutputCacheProviderCollection.cs: added

        * OutputCacheProvider.cs: added

        * OutputCacheModule.cs: uses the 4.0 extensible output cache
        provider model now (also internally in the 2.0 profile)
        OutputCacheProvider is retrieved on every request using
        HttpApplication.GetOutputCacheProviderName (4.0+). In the 2.0
        profile an instance of InMemoryOutputCacheProvider is always
        returned.

        * InMemoryOutputCacheProvider.cs: default output cache provider
        for ASP.NET 4.0, also used internally in the  2.0 profile.

        * CachedVaryBy.cs: made the generated key shorter

        * CacheItemPriorityQueueDebug.cs: debugging support for
        CacheItemPriorityQueue. Most of the code is compiled only when the
        DEBUG macro is defined. Debugging support includes recording of
        the queue operations sequence which is output to an XML file on
        appdomain shutdown. The recorded sequence files can be used to
        generate NUnit test cases for the priority queue (see
        ../Test/tools/README)

        * CacheItemPriorityQueue.cs: rewritten using an array based heap
        instead of a binary tree based one - implementation is simpler,
        faster and more elegant. Heap is initially 32 entries long and
        its size is doubled every time it fills up. After reaching a
        threshold (8192 entries currently) it is shrunk to the number of
        items + 1/3 of item count in order to preserve memory.

        * CacheItem.cs: added a Guid field to easier distinguish items
        (mostly for debugging purposes)

        * CacheDependency.cs: minor performance improvements

        * Cache.cs: better handling of timer periods

2010-02-03  Marek Habersack  <[email protected]>

        * HttpApplication.cs: GetOutputCacheProviderName returns the value
        of OutputCache.DefaultProviderName

        * HttpRuntime.cs: internal cache is used to hold the dependencies
        now.

2010-02-03  Marek Habersack  <[email protected]>

        * CacheItemPriorityQueueTest_generated.cs: added

        * CacheItemPriorityQueueTest.cs: added

2010-02-04  Marek Habersack  <[email protected]>

        * Helpers.cs: added a helper method for checking of HTML mentions
        any .NET exceptions.

2010-02-03  Marek Habersack  <[email protected]>

        * Makefile: added targets to compile cache priority queue tests
        generator and to generate the tests themselves

svn path=/trunk/mcs/; revision=150855
2010-02-04 13:53:55 +00:00
Marek Habersack dc4d82729f 2010-01-25 Marek Habersack <[email protected]>
* SqlCacheDependency.cs: added parameter checks to the
	constructors.
	Partially implemented 4.0 method CreateOutputCacheDependency

	* CacheItemUpdateReason.cs, CacheItemUpdateCallback.cs: added

	* CacheItem.cs: added OnUpdateCallback field

	* Cache.cs: implemented support for cache item update callback
	(3.5+)

	* AggregateCacheDependency.cs: added undocumented
	DependencyDispose method override

2010-01-25  Marek Habersack  <[email protected]>

	* SqlCacheDependencyTest.cs: added

svn path=/trunk/mcs/; revision=150130
2010-01-25 14:02:18 +00:00
Marek Habersack 90fd2a073c 2009-12-01 Marek Habersack <[email protected]>
* Cache.cs: ExpireItems dequeues the next item when a disabled
	item is found before continuing to look for items to expire. Fixes
	bug #559470. Patch from Adriaan van Kekem <[email protected]>,
	thanks.

svn path=/trunk/mcs/; revision=147213
2009-12-01 11:37:18 +00:00
Marek Habersack b40844116b More 1.1 code and NET_2_0 ifdefs removed
svn path=/trunk/mcs/; revision=145319
2009-11-03 20:19:37 +00:00
Marek Habersack 24df2e7a3f 2009-10-05 Marek Habersack <[email protected]>
* Cache.cs: if item expiration time exceeds the maximum value
	Timer accepts, use the latter - item will expire properly anyway,
	as the timer will be rescheduled for the item's expiration time
	once that item is bubbled to the top of the priority queue. Fixes
	bug #544171

svn path=/trunk/mcs/; revision=143384
2009-10-05 10:45:33 +00:00
Marek Habersack aa68b0b904 2009-09-26 Marek Habersack <[email protected]>
* CacheItemPriorityQueue.cs, CacheItem.cs, CacheItemEnumerator.cs:
	added

	* Cache.cs: factored out CacheItem and CacheItemEnumerator to
	separate files.
	Use reader-writer locks instead of Monitor.
	Added two 3.5sp1 properties - EffectivePrivateBytesLimit and
	EffectivePercentagePhysicalMemoryLimit.
	Added support for disabling cache item expiration.
	One timer is used to expire all timed items (instead of one timer
	per item). Timed items are kept in a priority queue.

svn path=/trunk/mcs/; revision=142664
2009-09-25 22:28:21 +00:00
Marek Habersack 4a3dce4bcd 2009-01-09 Marek Habersack <[email protected]>
* Cache.cs: System.Threading.Timer.Change takes a long, not an
	int. The maximum value of sliding expiration is 365 days
	(31536000000ms) which fits within the value range of long. The
	previous cast to int might yield negative values in certain
	situations which was the reason for bug #464221. Fixes bug #464221

svn path=/trunk/mcs/; revision=122839
2009-01-08 23:50:52 +00:00
Marek Habersack f345ffeea2 2008-10-21 Marek Habersack <[email protected]>
* CapabilitiesChecksum.cs: implement Hex and MapToHex more efficiently.

2008-10-21  Marek Habersack  <[email protected]>

	* OutputCacheModule.cs: seal the class.
	Made OnRawResponseRemoved a static method.

	* CachedVaryBy.cs: seal the class.
	Use portable line terminators instead of literal '\n'.

	* Cache.cs: seal the CacheItem and CacheItemEnumerator classes.

	* CacheDependency.cs: dispose the associated dependency in the
	DependencyDispose method.

	* CachedRawResponse.cs: seal the class

2008-10-21  Marek Habersack  <[email protected]>

	* CapabilitiesLoader.cs: seal BrowserData.
	Seal CapabilitiesLoader.
	Do not lock on typeof (CapabilitiesLoader) in GetCapabilities ().

svn path=/trunk/mcs/; revision=116583
2008-10-21 01:08:23 +00:00
Marek Habersack fcb0f8f40b 2008-08-11 Marek Habersack <[email protected]>
Pass onRemoveCallback along in Insert. Fixes bugs #324528 and
	#382644. Patch provided by Juraj Skripsky <[email protected]>,
	thanks!


svn path=/trunk/mcs/; revision=110125
2008-08-11 17:04:51 +00:00
Marek Habersack 3e0838c477 2008-08-11 Marek Habersack <[email protected]>
* Cache.cs: dispose item timer when removing an entry. Fixes bug
	#416076. Patch provided by Adriaan van Kekem
	<[email protected]>, thanks!

svn path=/trunk/mcs/; revision=110121
2008-08-11 16:13:47 +00:00
Marek Habersack 8681536fff 2008-05-23 Marek Habersack <[email protected]>
* Cache.cs: optimize lock usage

2008-05-23  Marek Habersack  <[email protected]>

	* SessionInProcHandler.cs, RemoteStateServer.cs: update for
	internal API change in System.Web.Caching.Cache.

svn path=/trunk/mcs/; revision=103946
2008-05-23 19:16:43 +00:00
Marek Habersack b92349a289 2008-04-28 Marek Habersack <[email protected]>
* Cache.cs: refactoring - move the timeout setting code to
	separate methods, so that it can be accessed from outside the
	class. Fixes bug #382644

2008-04-28  Marek Habersack  <[email protected]>

	* ISessionHandler.cs: added new method, Touch, to reset the item
	timeout.

	* SessionStateServerHandler.cs, SessionSQLServerHandler.cs,
	SessionInProcHandler.cs: added implementation of the
	ISessionHandler Touch method, to reset item timeout. Fixes bug
	#382644

	* StateServerItem.cs: made the Timeout property writable.

	* SessionStateModule.cs: reset the item timeout after
	OnSessionStart has returned. Fixes bug #382644

	* RemoteStateServer.cs: added a method to reset item timeout.

svn path=/trunk/mcs/; revision=102034
2008-04-28 13:35:02 +00:00
Geoff Norton 1efe2c5419 2008-03-18 Geoff Norton <[email protected]>
* Cache.cs:  MS allows calling Insert in a removed handler, we need to
	avoid double locking here otherwise the Insert will never succeed.


svn path=/trunk/mcs/; revision=98559
2008-03-18 21:15:06 +00:00
Vladimir Krasnov b91ee13c6b * Cache.cs: added DependencyCache property, a cache object for creating dependencies
* DataSourceCacheManager.cs: fixed SetCachedObject, fixed CacheDependency keys
* HttpRuntime.cs: fixed HttpRuntime, added Cache.DependencyCache initialization

svn path=/trunk/mcs/; revision=92049
2007-12-31 08:57:46 +00:00
Juraj Skripsky 6486fa984c 2007-12-19 Juraj Skripsky <[email protected]>
* Cache.cs: Replace periodic timer (60s) with per-cache-item expiration
	timers.

2007-12-19  Juraj Skripsky <[email protected]>

	* HttpContext.cs, HttpApplication.cs: Move timeout tracking from
	TimeoutManager into HttpContext. Replace periodic timeout checks with
	separate per-context timeout timers.  
	* HttpRuntime.cs: remove TimeoutManager.

2007-12-19  Juraj Skripsky  <[email protected]>

	* System.Web.dll.sources: removed TimeoutManager.cs


svn path=/trunk/mcs/; revision=91612
2007-12-19 11:27:00 +00:00
Juraj Skripsky 724c547041 2007-06-25 Juraj Skripsky <[email protected]>
* Cache.cs: Re-introduce "InvokePrivateCallbacks" accidentally
	removed in r80321.

2007-06-25 Juraj Skripsky <[email protected]>

	* HttpRuntime.cs (ShutdownAppDomain): Re-introduce call to
	"Cache.InvokePrivateCallbacks".


svn path=/trunk/mcs/; revision=80696
2007-06-25 17:11:48 +00:00
Marek Habersack 56c3bddbe6 2007-06-20 Marek Habersack <[email protected]>
* Cache.cs: Iterate over the entries when filling the ArrayList in the 2.0
	profile to avoid type cast exceptions.

svn path=/trunk/mcs/; revision=80340
2007-06-20 17:25:25 +00:00
Marek Habersack 0b80ac0b50 2007-06-20 Marek Habersack <[email protected]>
* OutputCacheModule.cs: use Context.InternalCache.

	* Cache.cs: 2.0 profile uses generic containers to keep the cache
	entries.
	Gotten rid of the InsertPrivate and InsertInternal methods. The
	latter was moved to one of the Insert overloads.
	Private entries are no longer handled specifically, because the
	internal cache is now kept in a separate object.

2007-06-20  Marek Habersack  <[email protected]>

	* AppResourcesCompiler.cs: use HttpRuntime.InternalCache to keep
	private entries.
	* CachingCompiler.cs: as above
	* AspGenerator.cs: as above

2007-06-20  Marek Habersack  <[email protected]>

	* DataSourceCacheManager.cs: use HttpContext.Current.InternalCache
	to keep private entries.
	* XmlDataSource.cs: as above

2007-06-20  Marek Habersack  <[email protected]>

	* SessionInProcHandler.cs: use HttpRuntime.InternalCache to keep
	private entries.

2007-06-20  Marek Habersack  <[email protected]>

	* SessionInProcHandler.cs: use HttpRuntime.InternalCache to keep
	the internal entries.

2007-06-20  Marek Habersack  <[email protected]>

	* BasePartialCachingControl.cs: use HttpRuntime.InternalCache to
	keep the private entries.

2007-06-20  Marek Habersack  <[email protected]>

	* HttpRuntime.cs: added new internal property, InternalCache, to
	keep all the internal cache entries instead of mixing them with
	the public cache ones.
	Do not invoke Cache.InvokePrivateCallbacks - this method no longer
	exists.

	* HttpResponse.cs: private entries are now kept in
	Context.InternalCache.

	* HttpContext.cs: added new internal property, InternalCache,
	which returns the HttpRuntime.InternalCache value.

Fixes bug #81690


svn path=/trunk/mcs/; revision=80321
2007-06-20 15:42:36 +00:00
Gonzalo Paniagua Javier a5af58e42a 2006-11-14 Marek Habersack <[email protected]>
* Cache.cs:
	* CacheDependency.cs:
	* AggregateCacheDependency.cs: implement this one.


svn path=/trunk/mcs/; revision=67862
2006-11-14 17:44:00 +00:00
Gonzalo Paniagua Javier 0d5ff18ed0 2006-08-03 Gonzalo Paniagua Javier <[email protected]>
* CacheDependency.cs:
	* Cache.cs: check dependencies on other cache keys. Fixes bug #79002.


svn path=/trunk/mcs/; revision=63303
2006-08-03 15:50:47 +00:00
Gonzalo Paniagua Javier f6aa6b8f53 2005-10-24 Gonzalo Paniagua Javier <[email protected]>
* System.Web.Caching/Cache.cs: new internal method.
	* System.Web/HttpRuntime.cs: invoke callbacks on private items in the
	cache before calling disposing the app. factory. This way we get
	notifications of removal for all sessions stored in the cache (InProc
	only). Fixes bug #76524.


svn path=/trunk/mcs/; revision=52113
2005-10-24 05:10:05 +00:00
Gonzalo Paniagua Javier df6ad348f6 2005-09-02 Gonzalo Paniagua Javier <[email protected]>
* Cache.cs: ignore exceptions thrown by removed item callbacks.


svn path=/trunk/mcs/; revision=49364
2005-09-02 19:04:56 +00:00
Sebastien Pouliot 96205ff6c0 2005-09-02 Sebastien Pouliot <[email protected]>
* Cache.cs: Added security permissions with Minimal level for
	AspNetHostingPermissionLevel (only LinkDemand as the class is sealed).
	* CacheDependency.cs: : Added security permissions with Minimal level 
	for AspNetHostingPermissionLevel (note class is sealed only in 1.x).



svn path=/trunk/mcs/; revision=49342
2005-09-02 13:29:54 +00:00
Lluis Sanchez 96d5d0dd77 2005-07-15 Lluis Sanchez Gual <[email protected]>
* Cache.cs: New implementation.
	* CacheDependency.cs: New implementation.

2005-08-26  Lluis Sanchez Gual  <[email protected]> 

	* CssStyleCollection.cs: Added some spacing.
	* HtmlTextWriter.cs: Made style and attribute tables static.
	  Implemented StaticGetStyleName().

2005-08-26  Lluis Sanchez Gual  <[email protected]> 

	* Style.cs: Implemented FillStyleAttributes, GetStyleAttributes and
	SetDirty.

svn path=/trunk/mcs/; revision=48924
2005-08-26 22:29:51 +00:00
Miguel de Icaza 4c004f75ed Remove
svn path=/trunk/mcs/; revision=48909
2005-08-26 20:38:24 +00:00
Eyal Alalouf cc09709c26 Destroy cahce in HttpRuntime.Dispose for TARGET_J2EE.
svn path=/trunk/mcs/; revision=47712
2005-07-26 16:33:04 +00:00
Gonzalo Paniagua Javier 3eb5ecafd7 2005-06-25 Gonzalo Paniagua Javier <[email protected]>
* Cache.cs: added new InsertPrivate overload.


svn path=/trunk/mcs/; revision=46507
2005-06-25 20:46:31 +00:00
Gonzalo Paniagua Javier a6e0d6f12b 2005-06-25 Gonzalo Paniagua Javier <[email protected]>
* Cache.cs: 
	* CacheEntry.cs: style. Removed doc. comments.


svn path=/trunk/mcs/; revision=46502
2005-06-25 19:23:08 +00:00
Gonzalo Paniagua Javier 35c816ff29 2005-04-28 Gonzalo Paniagua Javier <[email protected]>
* ExpiresBuckets.cs:
	* Cache.cs:
	* CacheExpires.cs: fix NullReferenceException thrown sometimes when
	using sliding expiration and under high load. Patch by Eyal Alayuf from
	Mainsoft.


svn path=/trunk/mcs/; revision=43705
2005-04-28 04:01:16 +00:00
Ben Maurer c06c79073a 2004-10-03 Ben Maurer <[email protected]>
* Cache.cs, CacheEntry.cs, CacheExpires.cs, ExpiresBuckets.cs:
	use UtcNow rather than Now.

svn path=/trunk/mcs/; revision=34640
2004-10-03 21:55:41 +00:00
Duncan Mak d1c09fcc67 Add licensing info
svn path=/trunk/mcs/; revision=30345
2004-06-24 20:59:43 +00:00
Patrik Torstensson a596fe4999 2004-05-27 Patrik Torstensson <[email protected]>
* CacheEntry.cs,CacheExpires.cs,ExpiresBucket.cs,
	  Cache.cs : Fixed deadlock issues, fixed
	  items not correctly being flushed, fixed update
	  of item when expiration has been updated more
	  than 1 min (placed in wrong bucket),
	  fixed deadlock during cache callback when item
	  is removed due to expiriation.

	  Rewrite of locking handling in Cache class, leading
	  to better performance and less bugs.

	  This rewrite is due to a number of bugs found
	  in the output caching during load (leading to memory
	  leaks and deadlocks)

svn path=/trunk/mcs/; revision=28254
2004-05-27 12:15:13 +00:00
Gonzalo Paniagua Javier 876e05bb03 2004-04-16 Gonzalo Paniagua Javier <[email protected]>
* Cache.cs: fix from Jan Jaros for NullRef (bug #56996).

svn path=/trunk/mcs/; revision=25583
2004-04-16 04:51:44 +00:00
Lluis Sanchez c589dd6958 * Cache.cs, CacheEntry.cs, ExpiresBuckets.cs: The value to use to specify
infinite timeout in ReaderWriterLock is -1, not 0.

svn path=/trunk/mcs/; revision=25148
2004-04-07 09:24:25 +00:00
Jackson Harper 80f98b141b * Cache.cs: Close entries that are removed.
* CacheDependency.cs: Use FileSystemWatcher instead of custom
	Watcher for file dependencies.
	* OutputCacheModule.cs: Make the varyby objects dependent on the
	cached page.

svn path=/trunk/mcs/; revision=22924
2004-02-09 22:00:05 +00:00
Jackson Harper ed9721a025 * Cache.cs: Return null when items are expired but have not been
removed yet.
	* OutputCacheModule.cs: Handle sliding expirations. Remove hacks
	checking if the item is expired, the cache no longer returns
	expired items.

svn path=/trunk/mcs/; revision=22103
2004-01-15 06:42:06 +00:00
Jackson Harper e9aae24f7c * Cache.cs: When using sliding expiration update the cache objects
expires time as well as the expires entry expire time because the
	objects expire time is checked when objects are pulled out. This
	fixex bug #52778.

svn path=/trunk/mcs/; revision=22100
2004-01-15 05:18:02 +00:00
Jackson Harper e2a4fa1f17 * Cache.cs: Add method to get CacheEntry objects.
svn path=/trunk/mcs/; revision=21692
2004-01-05 01:40:35 +00:00
Jackson Harper 54d9ed0618 * Cache.cs: New method so non public cache items can be added.
* CachedRawResponse.cs: New file - A snapshot of a response that
	is stored in the cache and can be used to create a new response.
	* OutputCacheModule.cs: Module for inserting and retrieving
	responses from the cache.

svn path=/trunk/mcs/; revision=20272
2003-11-20 11:50:24 +00:00
Gonzalo Paniagua Javier 46059274db 2003-03-13 Gonzalo Paniagua Javier <[email protected]>
* System.Web/HttpRuntime.cs: Cache no longer have a Dispose method.

	* System.Web/HttpServerUtility.cs: removed MonoTODO.

	* System.Web.Caching/Cache.cs:
	* System.Web.Caching/CacheDefinitions.cs:
	* System.Web.Caching/CacheDependency.cs:
	* System.Web.Caching/CacheEntry.cs:
	* System.Web.Caching/CacheExpires.cs:
	* System.Web.Caching/ExpiresBuckets.cs: reformatted, make class status
	page happier. Does not work yet (wait for the next patch).

	* System.Web.SessionState/HttpSessionState.cs: implemented CodePage.

	* System.Web.SessionState/SessionStateModule.cs: initial stuff to make
	it work.

svn path=/trunk/mcs/; revision=12480
2003-03-13 19:44:44 +00:00