J
Joel Barsotti
My website has different products and I've developed a nice little object
oreinted class library for them. I then use the objects for products and
such on many different pages. Especially with some products inheriting from
other objects and many of them needing to access the database to initialize
correctly I've created quite the load on my sql server. I was hoping to
alivate this via caching I was hoping do somthing like this.
public partial class TestCache : System.Web.UI.Page
{
protected Product myProduct;
protected void Page_Load(object sender, EventArgs e)
{
myProduct = new Product("productXYZ",
(string)Application["connString"], Cache)
}
}
public class Product
{
protected string connString;
protected int productID;
...
protected decimal price;
public Product(string productName, string newConnString, Cache
currentCache)
{
connString = newConnString
if (currentCache["prodcut-" +productName] != null)
{
this = (Product)currentCache["prodcut-" +productName];
}
else
{
initProduct(productName);
}
}
}
But alas, the this keyword is read only. Is there a way to accomplish this?
I'd rather not have to go through everypage and put both a cache check and
cache insert statement. And it seems redundant to create a wrapper class to
handle the caching.
I suppose I could just cache the database results in the iniProduct
function, but somehow that seems less elegant. Any help?
oreinted class library for them. I then use the objects for products and
such on many different pages. Especially with some products inheriting from
other objects and many of them needing to access the database to initialize
correctly I've created quite the load on my sql server. I was hoping to
alivate this via caching I was hoping do somthing like this.
public partial class TestCache : System.Web.UI.Page
{
protected Product myProduct;
protected void Page_Load(object sender, EventArgs e)
{
myProduct = new Product("productXYZ",
(string)Application["connString"], Cache)
}
}
public class Product
{
protected string connString;
protected int productID;
...
protected decimal price;
public Product(string productName, string newConnString, Cache
currentCache)
{
connString = newConnString
if (currentCache["prodcut-" +productName] != null)
{
this = (Product)currentCache["prodcut-" +productName];
}
else
{
initProduct(productName);
}
}
}
But alas, the this keyword is read only. Is there a way to accomplish this?
I'd rather not have to go through everypage and put both a cache check and
cache insert statement. And it seems redundant to create a wrapper class to
handle the caching.
I suppose I could just cache the database results in the iniProduct
function, but somehow that seems less elegant. Any help?