Files
kami_itunes_june/AppleBatch_June/SiteHelper.cs
danial cb905409f8 Refactor AppleBatch_June project:
- Removed DotRas library dependency in RasTools.cs, providing empty implementations for Connect and Disconnect methods.
- Updated context menu implementation in ReddemHelp.cs to use ToolStripMenuItem and ContextMenuStrip.
- Replaced caching mechanism in SiteHelper.cs with a custom dictionary-based implementation, removing reliance on HttpRuntime.Cache.
- Switched from JavaScriptSerializer to Newtonsoft.Json for JSON serialization/deserialization in multiple files (Tools.cs, addMaterial.cs).
- Added WebHeaderCollection property to HttpItem.cs for better header management.
- Deleted obsolete AssemblyInfo.cs file.
- Introduced apple_balance_query.py for querying Apple ID balance via Privacy Center, implementing authentication and balance retrieval logic.
2025-11-10 17:38:18 +08:00

57 lines
1.1 KiB
C#

using System;
using System.Collections.Generic;
namespace AppleBatch_June
{
public class SiteHelper
{
private static readonly Dictionary<string, CacheItem> _cache = new Dictionary<string, CacheItem>();
private static readonly object _lock = new object();
private class CacheItem
{
public object Value { get; set; }
public DateTime ExpiryTime { get; set; }
}
public static object GetCache(string CacheId)
{
lock (_lock)
{
if (_cache.TryGetValue(CacheId, out CacheItem item))
{
if (DateTime.Now < item.ExpiryTime)
{
return item.Value;
}
else
{
_cache.Remove(CacheId);
}
}
}
return null;
}
public static void SetCache(string CacheId, object objCache)
{
SetCache(CacheId, objCache, 60);
}
public static void SetCache(string CacheId, object objCache, int cacheDurationSeconds)
{
if (objCache != null)
{
lock (_lock)
{
_cache[CacheId] = new CacheItem
{
Value = objCache,
ExpiryTime = DateTime.Now.AddSeconds(cacheDurationSeconds)
};
}
}
}
}
}