29 using System.Reflection;
33 using OpenSim.Framework;
34 using OpenSim.Region.Framework.Interfaces;
35 using OpenSim.Region.Framework.Scenes;
93 [Extension(Path =
"/OpenSim/RegionModules", NodeName =
"RegionModule", Id =
"CenomeMemoryAssetCache")]
96 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
106 public const int DefaultMaxCount = 4096;
116 public const long DefaultMaxSize = 134217728;
121 public static readonly TimeSpan DefaultExpirationTime = TimeSpan.FromMinutes(30.0);
126 private ICnmCache<string, AssetBase> m_cache;
131 private int m_cachedCount;
139 private int m_debugEpoch;
144 private bool m_enabled;
149 private int m_getCount;
154 private int m_hitCount;
168 protected void Initialize(
long maximalSize,
int maximalCount, TimeSpan expirationTime)
170 if (maximalSize <= 0 || maximalCount <= 0)
177 if (expirationTime <= TimeSpan.Zero)
180 expirationTime = TimeSpan.MaxValue;
185 CnmSynchronizedCache<string, AssetBase>.Synchronized(
new CnmMemoryCache<string, AssetBase>(
186 maximalSize, maximalCount, expirationTime));
189 "[ASSET CACHE]: Cenome asset cache enabled (MaxSize = {0} bytes, MaxCount = {1}, ExpirationTime = {2})",
195 #region IImprovedAssetCache Members
202 return m_cache.TryGetValue(id, out asset);
217 long size = asset.Data != null ? asset.Data.Length : 1;
218 m_cache.Set(asset.ID, asset, size);
262 if (m_cache.TryGetValue(
id, out assetBase))
265 if (m_getCount == m_debugEpoch)
268 "[ASSET CACHE]: Cached = {0}, Get = {1}, Hits = {2}%, Size = {3} bytes, Avg. A. Size = {4} bytes",
271 ((double) m_hitCount / m_getCount) * 100.0,
273 m_cache.Size / m_cache.Count);
287 #region ISharedRegionModule Members
294 get {
return "CenomeMemoryAssetCache"; }
297 public Type ReplaceableInterface
338 IConfig moduleConfig = source.Configs[
"Modules" ];
339 if (moduleConfig == null)
342 string name = moduleConfig.GetString(
"AssetCaching");
348 long maxSize = DefaultMaxSize;
349 int maxCount = DefaultMaxCount;
350 TimeSpan expirationTime = DefaultExpirationTime;
352 IConfig assetConfig = source.Configs[
"AssetCache"];
353 if (assetConfig != null)
356 maxSize = assetConfig.GetLong(
"MaxSize", DefaultMaxSize);
357 maxCount = assetConfig.GetInt(
"MaxCount", DefaultMaxCount);
359 TimeSpan.FromMinutes(assetConfig.GetInt(
"ExpirationTime", (int)DefaultExpirationTime.TotalMinutes));
362 m_debugEpoch = assetConfig.GetInt(
"DebugEpoch", 0);
365 Initialize(maxSize, maxCount, expirationTime);
Cenome memory asset cache.
AssetBase Get(string id)
Get asset stored
void PostInitialise()
Initialization post handling.
void Cache(AssetBase asset)
Cache asset.
void Expire(string id)
Expire (remove) asset stored to cache.
Asset class. All Assets are reference by this class or a class derived from this class ...
void Initialize(long maximalSize, int maximalCount, TimeSpan expirationTime)
Initialize asset cache module, with custom parameters.
bool Check(string id)
Check whether an asset with the specified id exists in the cache.
void Initialise(IConfigSource source)
Initialize region module.
void Clear()
Clear asset cache.
void RemoveRegion(Scene scene)
Region is being removed.
void AddRegion(Scene scene)
New region is being added to server.
Interactive OpenSim region server
void RegionLoaded(Scene scene)
Region has been loaded.
void Close()
Close region module.