31 using System.Collections.Generic;
32 using System.Reflection;
33 using GlynnTucker.Cache;
36 using OpenSim.Framework;
37 using OpenSim.Region.Framework.Interfaces;
38 using OpenSim.Region.Framework.Scenes;
39 using OpenSim.Services.Interfaces;
43 [Extension(Path =
"/OpenSim/RegionModules", NodeName =
"RegionModule", Id =
"GlynnTuckerAssetCache")]
46 private static readonly ILog m_log =
48 MethodBase.GetCurrentMethod().DeclaringType);
50 private bool m_Enabled;
51 private ICache m_Cache;
53 private ulong m_Requests;
56 private uint m_DebugRate;
58 public Type ReplaceableInterface
65 get {
return "GlynnTuckerAssetCache"; }
70 IConfig moduleConfig = source.Configs[
"Modules"];
72 if (moduleConfig != null)
74 string name = moduleConfig.GetString(
"AssetCaching");
79 m_Cache =
new GlynnTucker.Cache.SimpleMemoryCache();
82 m_log.Info(
"[ASSET CACHE]: GlynnTucker asset cache enabled");
85 IConfig cacheConfig = source.Configs[
"AssetCache"];
86 if (cacheConfig != null)
87 m_DebugRate = (uint)cacheConfig.GetInt(
"DebugRate", 0);
120 return m_Cache.Contains(id);
126 m_Cache.AddOrUpdate(asset.ID, asset);
132 m_Cache.TryGet(id, out asset);
142 if (m_Cache.TryGet(
id, out asset))
151 private void Debug(Object asset)
160 if ((m_Requests % m_DebugRate) == 0)
161 m_log.DebugFormat(
"[ASSET CACHE]: Hit Rate {0} / {1} == {2}%", m_Hits, m_Requests, ((float)m_Hits / (
float)m_Requests) * 100.0f);
void Clear()
Clear the cache.
void Cache(AssetBase asset)
Cache the specified asset.
void Initialise(IConfigSource source)
This is called to initialize the region module. For shared modules, this is called exactly once...
void PostInitialise()
This is called exactly once after all the shared region-modules have been instanciated and IRegionMod...
void Expire(string id)
Expire an asset from the cache.
void RegionLoaded(Scene scene)
This will be called once for every scene loaded. In a shared module this will be multiple times in on...
Asset class. All Assets are reference by this class or a class derived from this class ...
bool Check(string id)
Check whether an asset with the specified id exists in the cache.
void Close()
This is the inverse to Initialise. After a Close(), this instance won't be usable anymore...
AssetBase Get(string id)
Get an asset by its id.
void RemoveRegion(Scene scene)
This is called whenever a Scene is removed. For shared modules, this can happen several times...
void AddRegion(Scene scene)
This is called whenever a Scene is added. For shared modules, this can happen several times...