diff options
author | Andrew Arnott <andrewarnott@gmail.com> | 2010-03-25 22:51:38 -0700 |
---|---|---|
committer | Andrew Arnott <andrewarnott@gmail.com> | 2010-03-25 22:51:38 -0700 |
commit | c65d00c276e894f3adb4aaaef0f1adcf0ed8882f (patch) | |
tree | 32966c3cc06fc82ce9a68310a6d87d7cef4a5729 | |
parent | 0d8fe1df1813e5f39a4db63affe9dbe5c7c84de3 (diff) | |
download | DotNetOpenAuth-c65d00c276e894f3adb4aaaef0f1adcf0ed8882f.zip DotNetOpenAuth-c65d00c276e894f3adb4aaaef0f1adcf0ed8882f.tar.gz DotNetOpenAuth-c65d00c276e894f3adb4aaaef0f1adcf0ed8882f.tar.bz2 |
Removed the unused ClearExpiredAssociations method.
4 files changed, 34 insertions, 48 deletions
diff --git a/src/DotNetOpenAuth/OpenId/AssociationMemoryStore.cs b/src/DotNetOpenAuth/OpenId/AssociationMemoryStore.cs index 13633b4..7a20fd5 100644 --- a/src/DotNetOpenAuth/OpenId/AssociationMemoryStore.cs +++ b/src/DotNetOpenAuth/OpenId/AssociationMemoryStore.cs @@ -20,12 +20,22 @@ namespace DotNetOpenAuth.OpenId { /// </remarks> internal class AssociationMemoryStore<TKey> : IAssociationStore<TKey> { /// <summary> + /// How many association store requests should occur between each spring cleaning. + /// </summary> + private const int PeriodicCleaningFrequency = 10; + + /// <summary> /// For Relying Parties, this maps OP Endpoints to a set of associations with that endpoint. /// For Providers, this keeps smart and dumb associations in two distinct pools. /// </summary> private Dictionary<TKey, Associations> serverAssocsTable = new Dictionary<TKey, Associations>(); /// <summary> + /// A counter to track how close we are to an expired association cleaning run. + /// </summary> + private int periodicCleaning; + + /// <summary> /// Stores a given association for later recall. /// </summary> /// <param name="distinguishingFactor">The distinguishing factor, either an OP Endpoint or smart/dumb mode.</param> @@ -38,6 +48,13 @@ namespace DotNetOpenAuth.OpenId { Associations server_assocs = this.serverAssocsTable[distinguishingFactor]; server_assocs.Set(association); + + unchecked { + this.periodicCleaning++; + } + if (this.periodicCleaning % PeriodicCleaningFrequency == 0) { + this.ClearExpiredAssociations(); + } } } @@ -88,17 +105,6 @@ namespace DotNetOpenAuth.OpenId { } /// <summary> - /// Clears all expired associations from the store. - /// </summary> - public void ClearExpiredAssociations() { - lock (this) { - foreach (Associations assocs in this.serverAssocsTable.Values) { - assocs.ClearExpired(); - } - } - } - - /// <summary> /// Gets the server associations for a given OP Endpoint or dumb/smart mode. /// </summary> /// <param name="distinguishingFactor">The distinguishing factor, either an OP Endpoint (for relying parties) or smart/dumb (for providers).</param> @@ -112,5 +118,16 @@ namespace DotNetOpenAuth.OpenId { return this.serverAssocsTable[distinguishingFactor]; } } + + /// <summary> + /// Clears all expired associations from the store. + /// </summary> + private void ClearExpiredAssociations() { + lock (this) { + foreach (Associations assocs in this.serverAssocsTable.Values) { + assocs.ClearExpired(); + } + } + } } } diff --git a/src/DotNetOpenAuth/OpenId/IAssociationStore.cs b/src/DotNetOpenAuth/OpenId/IAssociationStore.cs index 2376b0d..a3c5305 100644 --- a/src/DotNetOpenAuth/OpenId/IAssociationStore.cs +++ b/src/DotNetOpenAuth/OpenId/IAssociationStore.cs @@ -33,6 +33,12 @@ namespace DotNetOpenAuth.OpenId { /// <see cref="System.Uri"/> for consumers (to distinguish associations across servers) or /// <see cref="AssociationRelyingPartyType"/> for providers (to distinguish dumb and smart client associations). /// </typeparam> + /// <remarks> + /// Expired associations should be periodically cleared out of an association store. + /// This should be done frequently enough to avoid a memory leak, but sparingly enough + /// to not be a performance drain. Because this balance can vary by host, it is the + /// responsibility of the host to initiate this cleaning. + /// </remarks> public interface IAssociationStore<TKey> { /// <summary> /// Saves an <see cref="Association"/> for later recall. @@ -80,16 +86,5 @@ namespace DotNetOpenAuth.OpenId { /// before this call. /// </remarks> bool RemoveAssociation(TKey distinguishingFactor, string handle); - - /// <summary> - /// Clears all expired associations from the store. - /// </summary> - /// <remarks> - /// If another algorithm is in place to periodically clear out expired associations, - /// this method call may be ignored. - /// This should be done frequently enough to avoid a memory leak, but sparingly enough - /// to not be a performance drain. - /// </remarks> - void ClearExpiredAssociations(); } } diff --git a/src/DotNetOpenAuth/OpenId/Provider/StandardProviderApplicationStore.cs b/src/DotNetOpenAuth/OpenId/Provider/StandardProviderApplicationStore.cs index f33a655..4fa2d64 100644 --- a/src/DotNetOpenAuth/OpenId/Provider/StandardProviderApplicationStore.cs +++ b/src/DotNetOpenAuth/OpenId/Provider/StandardProviderApplicationStore.cs @@ -100,19 +100,6 @@ namespace DotNetOpenAuth.OpenId.Provider { return this.associationStore.RemoveAssociation(distinguishingFactor, handle); } - /// <summary> - /// Clears all expired associations from the store. - /// </summary> - /// <remarks> - /// If another algorithm is in place to periodically clear out expired associations, - /// this method call may be ignored. - /// This should be done frequently enough to avoid a memory leak, but sparingly enough - /// to not be a performance drain. - /// </remarks> - public void ClearExpiredAssociations() { - this.associationStore.ClearExpiredAssociations(); - } - #endregion #region INonceStore Members diff --git a/src/DotNetOpenAuth/OpenId/RelyingParty/StandardRelyingPartyApplicationStore.cs b/src/DotNetOpenAuth/OpenId/RelyingParty/StandardRelyingPartyApplicationStore.cs index 96dd8d8..9e1aa89 100644 --- a/src/DotNetOpenAuth/OpenId/RelyingParty/StandardRelyingPartyApplicationStore.cs +++ b/src/DotNetOpenAuth/OpenId/RelyingParty/StandardRelyingPartyApplicationStore.cs @@ -84,19 +84,6 @@ namespace DotNetOpenAuth.OpenId.RelyingParty { return this.associationStore.RemoveAssociation(distinguishingFactor, handle); } - /// <summary> - /// Clears all expired associations from the store. - /// </summary> - /// <remarks> - /// If another algorithm is in place to periodically clear out expired associations, - /// this method call may be ignored. - /// This should be done frequently enough to avoid a memory leak, but sparingly enough - /// to not be a performance drain. - /// </remarks> - public void ClearExpiredAssociations() { - this.associationStore.ClearExpiredAssociations(); - } - #endregion #region INonceStore Members |