diff options
Diffstat (limited to 'OpenSim/Region/CoreModules')
-rw-r--r-- | OpenSim/Region/CoreModules/Asset/GlynnTuckerAssetCache.cs | 172 |
1 files changed, 0 insertions, 172 deletions
diff --git a/OpenSim/Region/CoreModules/Asset/GlynnTuckerAssetCache.cs b/OpenSim/Region/CoreModules/Asset/GlynnTuckerAssetCache.cs deleted file mode 100644 index abe9b23..0000000 --- a/OpenSim/Region/CoreModules/Asset/GlynnTuckerAssetCache.cs +++ /dev/null | |||
@@ -1,172 +0,0 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSimulator Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | using log4net; | ||
29 | using System; | ||
30 | using System.IO; | ||
31 | using System.Collections.Generic; | ||
32 | using System.Reflection; | ||
33 | using GlynnTucker.Cache; | ||
34 | using Mono.Addins; | ||
35 | using Nini.Config; | ||
36 | using OpenSim.Framework; | ||
37 | using OpenSim.Region.Framework.Interfaces; | ||
38 | using OpenSim.Region.Framework.Scenes; | ||
39 | using OpenSim.Services.Interfaces; | ||
40 | |||
41 | namespace OpenSim.Region.CoreModules.Asset | ||
42 | { | ||
43 | [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "GlynnTuckerAssetCache")] | ||
44 | public class GlynnTuckerAssetCache : ISharedRegionModule, IAssetCache | ||
45 | { | ||
46 | private static readonly ILog m_log = | ||
47 | LogManager.GetLogger( | ||
48 | MethodBase.GetCurrentMethod().DeclaringType); | ||
49 | |||
50 | private bool m_Enabled; | ||
51 | private ICache m_Cache; | ||
52 | private ulong m_Hits; | ||
53 | private ulong m_Requests; | ||
54 | |||
55 | // Instrumentation | ||
56 | private uint m_DebugRate; | ||
57 | |||
58 | public Type ReplaceableInterface | ||
59 | { | ||
60 | get { return null; } | ||
61 | } | ||
62 | |||
63 | public string Name | ||
64 | { | ||
65 | get { return "GlynnTuckerAssetCache"; } | ||
66 | } | ||
67 | |||
68 | public void Initialise(IConfigSource source) | ||
69 | { | ||
70 | IConfig moduleConfig = source.Configs["Modules"]; | ||
71 | |||
72 | if (moduleConfig != null) | ||
73 | { | ||
74 | string name = moduleConfig.GetString("AssetCaching"); | ||
75 | //m_log.DebugFormat("[ASSET CACHE] name = {0} (this module's name: {1}). Sync? ", name, Name, m_Cache.IsSynchronized); | ||
76 | |||
77 | if (name == Name) | ||
78 | { | ||
79 | m_Cache = new GlynnTucker.Cache.SimpleMemoryCache(); | ||
80 | m_Enabled = true; | ||
81 | |||
82 | m_log.Info("[ASSET CACHE]: GlynnTucker asset cache enabled"); | ||
83 | |||
84 | // Instrumentation | ||
85 | IConfig cacheConfig = source.Configs["AssetCache"]; | ||
86 | if (cacheConfig != null) | ||
87 | m_DebugRate = (uint)cacheConfig.GetInt("DebugRate", 0); | ||
88 | } | ||
89 | } | ||
90 | } | ||
91 | |||
92 | public void PostInitialise() | ||
93 | { | ||
94 | } | ||
95 | |||
96 | public void Close() | ||
97 | { | ||
98 | } | ||
99 | |||
100 | public void AddRegion(Scene scene) | ||
101 | { | ||
102 | if (m_Enabled) | ||
103 | scene.RegisterModuleInterface<IAssetCache>(this); | ||
104 | } | ||
105 | |||
106 | public void RemoveRegion(Scene scene) | ||
107 | { | ||
108 | } | ||
109 | |||
110 | public void RegionLoaded(Scene scene) | ||
111 | { | ||
112 | } | ||
113 | |||
114 | //////////////////////////////////////////////////////////// | ||
115 | // IAssetCache | ||
116 | // | ||
117 | |||
118 | public bool Check(string id) | ||
119 | { | ||
120 | return m_Cache.Contains(id); | ||
121 | } | ||
122 | |||
123 | public void Cache(AssetBase asset) | ||
124 | { | ||
125 | if (asset != null) | ||
126 | m_Cache.AddOrUpdate(asset.ID, asset); | ||
127 | } | ||
128 | |||
129 | public void CacheNegative(string id) | ||
130 | { | ||
131 | // We don't do negative caching | ||
132 | } | ||
133 | |||
134 | public bool Get(string id, out AssetBase asset) | ||
135 | { | ||
136 | Object a = null; | ||
137 | m_Cache.TryGet(id, out a); | ||
138 | |||
139 | Debug(a); | ||
140 | |||
141 | asset = (AssetBase)a; | ||
142 | return true; | ||
143 | } | ||
144 | |||
145 | public void Expire(string id) | ||
146 | { | ||
147 | Object asset = null; | ||
148 | if (m_Cache.TryGet(id, out asset)) | ||
149 | m_Cache.Remove(id); | ||
150 | } | ||
151 | |||
152 | public void Clear() | ||
153 | { | ||
154 | m_Cache.Clear(); | ||
155 | } | ||
156 | |||
157 | private void Debug(Object asset) | ||
158 | { | ||
159 | // Temporary instrumentation to measure the hit/miss rate | ||
160 | if (m_DebugRate > 0) | ||
161 | { | ||
162 | ++m_Requests; | ||
163 | if (asset != null) | ||
164 | ++m_Hits; | ||
165 | |||
166 | if ((m_Requests % m_DebugRate) == 0) | ||
167 | m_log.DebugFormat("[ASSET CACHE]: Hit Rate {0} / {1} == {2}%", m_Hits, m_Requests, ((float)m_Hits / (float)m_Requests) * 100.0f); | ||
168 | } | ||
169 | // End instrumentation | ||
170 | } | ||
171 | } | ||
172 | } | ||