banshee r3070 - in trunk/banshee: . src/Core/Hyena src/Core/Hyena/Hyena.Data src/Core/Hyena/Hyena.Data.Sqlite
- From: gburt svn gnome org
- To: svn-commits-list gnome org
- Subject: banshee r3070 - in trunk/banshee: . src/Core/Hyena src/Core/Hyena/Hyena.Data src/Core/Hyena/Hyena.Data.Sqlite
- Date: Mon, 28 Jan 2008 22:16:46 +0000 (GMT)
Author: gburt
Date: Mon Jan 28 22:16:46 2008
New Revision: 3070
URL: http://svn.gnome.org/viewvc/banshee?rev=3070&view=rev
Log:
2008-01-28 Gabriel Burt <gabriel burt gmail com>
* src/Core/Hyena/Hyena.Data/ModelCache.cs:
* src/Core/Hyena/Hyena.Data/ArrayModelCache.cs:
* src/Core/Hyena/Hyena.Data/DictionaryModelCache.cs:
* src/Core/Hyena/Makefile.am: Implement different managed caching
strategies in subclasses of ModelCache.
* src/Core/Hyena/Hyena.Data.Sqlite/SqliteModelCache.cs: Subclass from
DictionaryModelCache for now (no practical change for now).
Added:
trunk/banshee/src/Core/Hyena/Hyena.Data/ArrayModelCache.cs
trunk/banshee/src/Core/Hyena/Hyena.Data/DictionaryModelCache.cs
Modified:
trunk/banshee/ChangeLog
trunk/banshee/src/Core/Hyena/Hyena.Data.Sqlite/SqliteModelCache.cs
trunk/banshee/src/Core/Hyena/Hyena.Data/ModelCache.cs
trunk/banshee/src/Core/Hyena/Makefile.am
Modified: trunk/banshee/src/Core/Hyena/Hyena.Data.Sqlite/SqliteModelCache.cs
==============================================================================
--- trunk/banshee/src/Core/Hyena/Hyena.Data.Sqlite/SqliteModelCache.cs (original)
+++ trunk/banshee/src/Core/Hyena/Hyena.Data.Sqlite/SqliteModelCache.cs Mon Jan 28 22:16:46 2008
@@ -32,7 +32,7 @@
namespace Hyena.Data.Sqlite
{
- public class SqliteModelCache<T> : ModelCache<T>
+ public class SqliteModelCache<T> : DictionaryModelCache<T>
{
private HyenaSqliteConnection connection;
private ICacheableDatabaseModel model;
@@ -147,7 +147,7 @@
public override int Reload ()
{
- InvalidateManagedCache ();
+ Clear ();
//using (new Timer (String.Format ("Generating cache table for {0}", model))) {
connection.Execute (reload_sql + model.ReloadFragment);
//}
@@ -162,7 +162,7 @@
select_range_command.ApplyValues (offset, limit);
using (IDataReader reader = connection.ExecuteReader (select_range_command)) {
while (reader.Read ()) {
- if (!Contains (offset)) {
+ if (!ContainsKey (offset)) {
Add (offset, provider.Load (reader, offset));
}
offset++;
@@ -194,7 +194,7 @@
} else {
//Console.WriteLine ("Found existing cache for {0}: {1}", id, uid);
warm = true;
- InvalidateManagedCache ();
+ Clear ();
UpdateCount ();
}
}
Added: trunk/banshee/src/Core/Hyena/Hyena.Data/ArrayModelCache.cs
==============================================================================
--- (empty file)
+++ trunk/banshee/src/Core/Hyena/Hyena.Data/ArrayModelCache.cs Mon Jan 28 22:16:46 2008
@@ -0,0 +1,76 @@
+//
+// ArrayModelCache.cs
+//
+// Author:
+// Gabriel Burt <gburt novell com>
+//
+// Copyright (C) 2007 Novell, Inc.
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+using System;
+
+namespace Hyena.Data
+{
+ public abstract class ArrayModelCache<T> : ModelCache<T>
+ {
+ protected T [] cache;
+ protected int offset = -1;
+ protected int limit = 0;
+
+ public ArrayModelCache (ICacheableModel model) : base (model)
+ {
+ cache = new T [model.FetchCount];
+ }
+
+ public override bool ContainsKey (int i)
+ {
+ return (i >= offset &&
+ i <= (offset + limit));
+ }
+
+ public override void Add (int i, T item)
+ {
+ if (cache.Length != model.FetchCount) {
+ cache = new T [model.FetchCount];
+ Clear ();
+ }
+
+ if (offset == -1 || i < offset || i >= (offset + cache.Length)) {
+ offset = i;
+ limit = 0;
+ }
+
+ cache [i - offset] = item;
+ limit++;
+ }
+
+ public override T this [int i] {
+ get { return cache [i - offset]; }
+ }
+
+ public override void Clear ()
+ {
+ offset = -1;
+ limit = 0;
+ }
+ }
+}
Added: trunk/banshee/src/Core/Hyena/Hyena.Data/DictionaryModelCache.cs
==============================================================================
--- (empty file)
+++ trunk/banshee/src/Core/Hyena/Hyena.Data/DictionaryModelCache.cs Mon Jan 28 22:16:46 2008
@@ -0,0 +1,62 @@
+//
+// DictionaryModelCache.cs
+//
+// Author:
+// Gabriel Burt <gburt novell com>
+//
+// Copyright (C) 2007 Novell, Inc.
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+using System;
+using System.Collections.Generic;
+
+namespace Hyena.Data
+{
+ public abstract class DictionaryModelCache<T> : ModelCache<T>
+ {
+ protected Dictionary<int, T> cache;
+
+ public DictionaryModelCache (ICacheableModel model) : base (model)
+ {
+ cache = new Dictionary<int, T> ();
+ }
+
+ public override bool ContainsKey (int i)
+ {
+ return cache.ContainsKey (i);
+ }
+
+ public override void Add (int i, T item)
+ {
+ cache.Add (i, item);
+ }
+
+ public override T this [int i] {
+ get { return cache [i]; }
+ }
+
+ public override void Clear ()
+ {
+ cache.Clear ();
+ }
+ }
+}
Modified: trunk/banshee/src/Core/Hyena/Hyena.Data/ModelCache.cs
==============================================================================
--- trunk/banshee/src/Core/Hyena/Hyena.Data/ModelCache.cs (original)
+++ trunk/banshee/src/Core/Hyena/Hyena.Data/ModelCache.cs Mon Jan 28 22:16:46 2008
@@ -33,8 +33,7 @@
{
public abstract class ModelCache<T>
{
- private ICacheableModel model;
- private Dictionary<int, T> cache = new Dictionary<int, T> ();
+ protected ICacheableModel model;
public ModelCache (ICacheableModel model)
{
@@ -43,41 +42,26 @@
public virtual T GetValue (int index)
{
- if (cache.ContainsKey (index))
- return cache[index];
+ if (ContainsKey (index))
+ return this[index];
FetchSet (index, model.FetchCount);
- if (cache.ContainsKey (index))
- return cache[index];
+ if (ContainsKey (index))
+ return this[index];
return default (T);
}
- protected virtual bool Contains (int key)
- {
- return cache.ContainsKey (key);
- }
-
- protected virtual void Add (int key, T value)
- {
- cache.Add (key, value);
- }
-
// Responsible for fetching a set of items and placing them in the cache
protected abstract void FetchSet (int offset, int limit);
// Reset the cache and return the total # of items in the model
public abstract int Reload ();
- public virtual void Clear ()
- {
- InvalidateManagedCache ();
- }
-
- protected void InvalidateManagedCache ()
- {
- cache.Clear ();
- }
+ public abstract bool ContainsKey (int i);
+ public abstract void Add (int i, T item);
+ public abstract T this[int i] { get; }
+ public abstract void Clear ();
}
}
Modified: trunk/banshee/src/Core/Hyena/Makefile.am
==============================================================================
--- trunk/banshee/src/Core/Hyena/Makefile.am (original)
+++ trunk/banshee/src/Core/Hyena/Makefile.am Mon Jan 28 22:16:46 2008
@@ -34,6 +34,8 @@
Hyena.Data.Sqlite/ICacheableDatabaseModel.cs \
Hyena.Data.Sqlite/SqliteModelCache.cs \
Hyena.Data.Sqlite/SqliteModelProvider.cs \
+ Hyena.Data/ArrayModelCache.cs \
+ Hyena.Data/DictionaryModelCache.cs \
Hyena.Data/ColumnDescription.cs \
Hyena.Data/ICacheableModel.cs \
Hyena.Data/ICareAboutView.cs \
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]