Hello I am currently developing my masters project and am relativly new to C#
I am having a problem with my Cache. In settings.settin gs I have placed the following after my connection setting:
DefaultCacheDur ation_Day Int Application 1
DefaultCacheDur ation_Hours Int Application 0
DefaultCacheDur ation_Minutes Int Application 0
I then have a cache.cs:
My error message is An object reference is required for the non-static field, method, or property 'Forestry.Schoo lLibrary.Proper ties.Settings.D efaultCacheDura tion_Hours.get'
and this appears in my connection.cs which is as follows:
I'm not sure if I have provided all the relevant information, but if anyone could help me figure this out it would be greatly appreciated
many thanks
Rachel
I am having a problem with my Cache. In settings.settin gs I have placed the following after my connection setting:
DefaultCacheDur ation_Day Int Application 1
DefaultCacheDur ation_Hours Int Application 0
DefaultCacheDur ation_Minutes Int Application 0
I then have a cache.cs:
Code:
using System;
using System.Collections;
using System.Collections.Generic;
using System.Web;
using System.Web.Caching;
using Forestry.SchoolLibrary.Properties;
namespace Forestry.SchoolLibrary.Impl
{
public class Cache
{
private static System.Web.Caching.Cache cache;
private static TimeSpan timeSpan = new TimeSpan(
Settings.Default.DefaultCacheDuration_Days,
Settings.Default.DefaultCacheDuration_Hours,
Settings.Default.DefaultCacheDuration_Minutes, 0);
static Cache()
{
cache = HttpContext.Current.Cache;
}
public static object Get(string cache_key)
{
return cache.Get(cache_key);
}
public static List<string> GetCacheKeys()
{
List<string> keys = new List<string>();
IDictionaryEnumerator ca = cache.GetEnumerator();
while (ca.MoveNext())
{
keys.Add(ca.Key.ToString());
}
return keys;
}
public static void Set(string cache_key, object cache_object)
{
Set(cache_key, cache_object, timeSpan);
}
public static void Set(string cache_key, object cache_object, DateTime expiration)
{
Set(cache_key, cache_object, expiration, CacheItemPriority.Normal);
}
public static void Set(string cache_key, object cache_object, TimeSpan expiration)
{
Set(cache_key, cache_object, expiration, CacheItemPriority.Normal);
}
public static void Set(string cache_key, object cache_object, DateTime expiration, CacheItemPriority priority)
{
cache.Insert(cache_key, cache_object, null, expiration, System.Web.Caching.Cache.NoSlidingExpiration, priority, null);
}
public static void Set(string cache_key, object cache_object, TimeSpan expiration, CacheItemPriority priority)
{
cache.Insert(cache_key, cache_object, null, System.Web.Caching.Cache.NoAbsoluteExpiration, expiration, priority, null);
}
public static void Delete(string cache_key)
{
if (Exists(cache_key))
cache.Remove(cache_key);
}
public static bool Exists(string cache_key)
{
if (cache[cache_key] != null)
return true;
else
return false;
}
public static void Flush()
{
foreach (string s in GetCacheKeys())
{
Delete(s);
}
}
}
}
and this appears in my connection.cs which is as follows:
Code:
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Data.Linq;
using System.Text;
using System.Xml;
using Forestry.SchoolLibrary.Domain;
using Forestry.SchoolLibrary.Properties;
namespace Forestry.SchoolLibrary.DataAccess.Impl
{
public class Connection
{
public SchoolDataContext GetContext()
{
string connString = "";
try
{
XmlDocument doc = new XmlDocument();
doc.Load("ConnectionStringToUse.xml");
XmlNodeList xnl = doc.GetElementsByTagName("environment");
XmlElement xe = (XmlElement)xnl[0];
switch (xe.InnerText.ToString().ToLower())
{
case "local":
connString = Settings.DefaultCacheDuration_Hours.SchoolConnectionStringLocal;
break;
case "development":
connString = Settings.DefaultCacheDuration_Hours.SchoolConnectionStringDevelopment;
break;
case "production":
connString = Settings.DefaultCacheDuration_Hours.SchoolConnectionStringProduction;
break;
default:
throw new Exception("No connection string defined in app.config!");
}
}
catch
{
connString = Settings.DefaultCacheDuration_Hours.SchoolConnectionStringLocal;
}
SchoolDataContext fdc = new SchoolDataContext(connString);
return fdc;
}
}
}
many thanks
Rachel
Comment