DocSpace-buildtools/common/ASC.Common/Collections/HttpRequestDictionary.cs

65 lines
1.6 KiB
C#
Raw Normal View History

namespace ASC.Collections;
public sealed class HttpRequestDictionary<T> : CachedDictionaryBase<T>
{
Merge branch 'feature/backend-refactor' into feature/asc-common-refactor # Conflicts: # common/ASC.Api.Core/GlobalUsings.cs # common/ASC.Common/Caching/AscCache.cs # common/ASC.Common/Collections/CachedDictionaryBase.cs # common/ASC.Common/Collections/HttpRequestDictionary.cs # common/ASC.Common/DIHelper.cs # common/ASC.Common/Data/StreamExtension.cs # common/ASC.Common/Data/TempStream.cs # common/ASC.Common/DependencyInjection/AutofacExtension.cs # common/ASC.Common/Logging/Log.cs # common/ASC.Common/Logging/SelfCleaningTarget.cs # common/ASC.Common/Logging/SpecialFolderPathConverter.cs # common/ASC.Common/Mapping/MappingProfile.cs # common/ASC.Common/Security/AscRandom.cs # common/ASC.Common/Security/Authorizing/AuthorizingException.cs # common/ASC.Common/Security/Authorizing/Constants.cs # common/ASC.Common/Security/Authorizing/Domain/Role.cs # common/ASC.Common/Security/Cryptography/Hasher.cs # common/ASC.Common/Threading/DistributedTask.cs # common/ASC.Common/Threading/DistributedTaskQueue.cs # common/ASC.Common/Utils/DnsLookup.cs # common/ASC.Common/Utils/HtmlUtil.cs # common/ASC.Common/Utils/HttpRequestExtensions.cs # common/ASC.Common/Utils/JsonWebToken.cs # common/ASC.Common/Utils/MailAddressUtils.cs # common/ASC.Common/Utils/RandomString.cs # common/ASC.Common/Utils/TimeZoneConverter/TimeZoneConverter.cs # common/ASC.Common/Utils/VelocityFormatter.cs # common/ASC.Common/Utils/Wildcard.cs # common/ASC.Common/Web/MimeMapping.cs # common/ASC.Common/Web/VirtualPathUtility.cs # common/services/ASC.ClearEvents/Program.cs # products/ASC.Files/Core/ThirdPartyApp/BoxApp.cs # products/ASC.Files/Core/ThirdPartyApp/GoogleDriveApp.cs
2022-02-11 13:17:55 +00:00
private readonly HttpContext _httpContext;
public HttpRequestDictionary(HttpContext httpContext, string baseKey)
{
Condition = (T) => true;
BaseKey = baseKey;
_httpContext = httpContext;
}
public override void Reset(string rootKey, string key)
{
if (_httpContext != null)
{
var builtkey = BuildKey(key, rootKey);
_httpContext.Items[builtkey] = null;
}
}
public override void Add(string rootkey, string key, T newValue)
{
if (_httpContext != null)
{
var builtkey = BuildKey(key, rootkey);
_httpContext.Items[builtkey] = new CachedItem(newValue);
}
}
2022-02-08 11:07:28 +00:00
protected override object GetObjectFromCache(string fullKey)
{
return _httpContext?.Items[fullKey];
}
2022-02-08 11:07:28 +00:00
protected override bool FitsCondition(object cached)
{
return cached is CachedItem;
}
2022-02-08 11:07:28 +00:00
protected override T ReturnCached(object objectCache)
{
return ((CachedItem)objectCache).Value;
}
protected override void OnHit(string fullKey) { }
protected override void OnMiss(string fullKey) { }
protected override void InsertRootKey(string rootKey)
{
//We can't expire in HtppContext in such way
}
Merge branch 'feature/backend-refactor' into feature/asc-common-refactor # Conflicts: # common/ASC.Api.Core/GlobalUsings.cs # common/ASC.Common/Caching/AscCache.cs # common/ASC.Common/Collections/CachedDictionaryBase.cs # common/ASC.Common/Collections/HttpRequestDictionary.cs # common/ASC.Common/DIHelper.cs # common/ASC.Common/Data/StreamExtension.cs # common/ASC.Common/Data/TempStream.cs # common/ASC.Common/DependencyInjection/AutofacExtension.cs # common/ASC.Common/Logging/Log.cs # common/ASC.Common/Logging/SelfCleaningTarget.cs # common/ASC.Common/Logging/SpecialFolderPathConverter.cs # common/ASC.Common/Mapping/MappingProfile.cs # common/ASC.Common/Security/AscRandom.cs # common/ASC.Common/Security/Authorizing/AuthorizingException.cs # common/ASC.Common/Security/Authorizing/Constants.cs # common/ASC.Common/Security/Authorizing/Domain/Role.cs # common/ASC.Common/Security/Cryptography/Hasher.cs # common/ASC.Common/Threading/DistributedTask.cs # common/ASC.Common/Threading/DistributedTaskQueue.cs # common/ASC.Common/Utils/DnsLookup.cs # common/ASC.Common/Utils/HtmlUtil.cs # common/ASC.Common/Utils/HttpRequestExtensions.cs # common/ASC.Common/Utils/JsonWebToken.cs # common/ASC.Common/Utils/MailAddressUtils.cs # common/ASC.Common/Utils/RandomString.cs # common/ASC.Common/Utils/TimeZoneConverter/TimeZoneConverter.cs # common/ASC.Common/Utils/VelocityFormatter.cs # common/ASC.Common/Utils/Wildcard.cs # common/ASC.Common/Web/MimeMapping.cs # common/ASC.Common/Web/VirtualPathUtility.cs # common/services/ASC.ClearEvents/Program.cs # products/ASC.Files/Core/ThirdPartyApp/BoxApp.cs # products/ASC.Files/Core/ThirdPartyApp/GoogleDriveApp.cs
2022-02-11 13:17:55 +00:00
private sealed class CachedItem
{
internal T Value { get; set; }
2022-02-08 11:07:28 +00:00
internal CachedItem(T value)
{
Value = value;
}
}
2019-05-15 14:56:09 +00:00
}