473,395 Members | 1,530 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Winforms Data Caching

I've seen a few examples on how to cache data in a WinForms GUI, just after
some thought on the best solution. The data I'm trying to cache will be
generally be small collections of Business Objects (eg Lookup data)

1) Using the Web Cache objects

2) Using AppDomain.CurrentDomain.SetData

3) Using the Caching Application Block

4) Using a static variable \ method & implement a Singleton approach

Any ideas on what offers the best performance with least pitfalls...?

Thanks
Jan 20 '06 #1
4 2701
Term "caching" means that you create a store namely cache, where
often-accessed entities are placed.
There are different caching strategies, which depend on data being cached.
Also the important thing is that how do you want to access the data.

The common approach ( and the quickest) will be to create a Hashtable and
use it as a cache store.
However, in .NET 2.0 there is generic dictionary Dictionary<T, K> that can
be used for caching, if your data keys ( identifiers ) are simple types
(boxing will be avoided ).

P.S. The above said is the common approach, but if you have to cache some
specific data then specific cache will presumaply give better performance if
correctly designed.

--
Vadym Stetsyak aka Vadmyst
http://vadmyst.blogspot.com

"DylanM" <Dy****@discussions.microsoft.com> wrote in message
news:54**********************************@microsof t.com...
I've seen a few examples on how to cache data in a WinForms GUI, just
after
some thought on the best solution. The data I'm trying to cache will be
generally be small collections of Business Objects (eg Lookup data)

1) Using the Web Cache objects

2) Using AppDomain.CurrentDomain.SetData

3) Using the Caching Application Block

4) Using a static variable \ method & implement a Singleton approach

Any ideas on what offers the best performance with least pitfalls...?

Thanks

Jan 20 '06 #2
Thanks for reply.

I basically have lookup data that isn't going to change while the user has
the GUI loaded. Instead of going to the database each time to get this
information, I'm just storing the data in memory and retrieving it from
there.

Since this is lookup data, its a small collection of objects (eg; collection
of 'SalesType' object that is fairly simple, exposes ID \ Description \ Code
fields). I just want to store the entire collection somewhere for easy
retrieval.

I've tested the following code, seems to work OK...

public static ObjectSet SalesTypes
{
get
{
ObjectSet salesTypes;

if (AppDomain.CurrentDomain.GetData("salesTypes") == null)
{
DataTable data = Manager.GetData(typeof(SalesType);
salesTypes= new ObjectSet(typeof(SalesType));

foreach (DataRow dr in data.Rows)
{
SalesType salesType = new SalesType (Convert.ToInt16(dr["st_id_pk"]),
dr["st_description"].ToString());
salesTypes.Add(salesType.ID, salesType);
}

AppDomain.CurrentDomain.SetData("salesTypes", salesTypes);
}
else
{
salesTypes = (ObjectSet) AppDomain.CurrentDomain.GetData("salesTypes");
}

return salesTypes;
}
}

I suppose the same result could be achieved with a static member variable
etc....just wondering how others are approaching this area.

Thanks

"Vadym Stetsyak" wrote:
Term "caching" means that you create a store namely cache, where
often-accessed entities are placed.
There are different caching strategies, which depend on data being cached.
Also the important thing is that how do you want to access the data.

The common approach ( and the quickest) will be to create a Hashtable and
use it as a cache store.
However, in .NET 2.0 there is generic dictionary Dictionary<T, K> that can
be used for caching, if your data keys ( identifiers ) are simple types
(boxing will be avoided ).

P.S. The above said is the common approach, but if you have to cache some
specific data then specific cache will presumaply give better performance if
correctly designed.

--
Vadym Stetsyak aka Vadmyst
http://vadmyst.blogspot.com


Jan 20 '06 #3
Yes, the result will be the same as long as you use string ids ( keys ).

AppDomain internally uses hashtable to store values, however, I'd recommed
you to use
Hashtable instead of AppDomain.

The reason is that AppDomain contains predefined system entries that are
inserted when the application domain is created. That is if one of your keys
will coincide with the predefined entry - you will get an exception.

If you can guarantee that none of your keys will be from the following set,
then you can use it, however better not. :8-)

Predefined values in AppDomain are:
"APPBASE"
ApplicationBase

"LOADER_OPTIMIZATION"
LoaderOptimization

"APP_CONFIG_FILE"
ConfigurationFile

"DYNAMIC_BASE"
DynamicBase

"DEV_PATH"
(no property)

"APP_NAME"
ApplicationName

"PRIVATE_BINPATH"
PrivateBinPath

"BINPATH_PROBE_ONLY"
PrivateBinPathProbe

"SHADOW_COPY_DIRS"
ShadowCopyDirectories

"FORCE_CACHE_INSTALL"
ShadowCopyFiles

"CACHE_BASE"
CachePath

--
Vadym Stetsyak aka Vadmyst
http://vadmyst.blogspot.com
Jan 20 '06 #4
Thanks Vadym - I'll give that a go!

"Vadym Stetsyak" wrote:
Yes, the result will be the same as long as you use string ids ( keys ).

AppDomain internally uses hashtable to store values, however, I'd recommed
you to use
Hashtable instead of AppDomain.

The reason is that AppDomain contains predefined system entries that are
inserted when the application domain is created. That is if one of your keys
will coincide with the predefined entry - you will get an exception.

If you can guarantee that none of your keys will be from the following set,
then you can use it, however better not. :8-)

Predefined values in AppDomain are:
"APPBASE"
ApplicationBase

"LOADER_OPTIMIZATION"
LoaderOptimization

"APP_CONFIG_FILE"
ConfigurationFile

"DYNAMIC_BASE"
DynamicBase

"DEV_PATH"
(no property)

"APP_NAME"
ApplicationName

"PRIVATE_BINPATH"
PrivateBinPath

"BINPATH_PROBE_ONLY"
PrivateBinPathProbe

"SHADOW_COPY_DIRS"
ShadowCopyDirectories

"FORCE_CACHE_INSTALL"
ShadowCopyFiles

"CACHE_BASE"
CachePath

--
Vadym Stetsyak aka Vadmyst
http://vadmyst.blogspot.com

Jan 20 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Sara T. | last post by:
Can I add some data to data grid control on the fly by not connecting to database ? I mean I need to put data to data grid control on the memory, I need to use it ro manage page such as next and...
1
by: Julia | last post by:
Hi, I have basic questions regarding ASP.NET site I am going to use Microsoft application configuration block and I wonder 1.does caching read only data in the application can hurt ...
0
by: Dino Chiesa [Microsoft] | last post by:
If you develop WinForms or WebForms clients that consume webservices, and display the results in a DataGrid, you may be interested in a helper class I found recently. It is the CollectionView...
1
by: Vinit | last post by:
Hello I have a C# application and am caching some data on the client side by using a HashTable. Is there a way I can set Cache dependencies like a time factor by which my cache is updated by...
4
by: 3Cooks | last post by:
I have a windows application written in Visual Basic 6.0 that is going to be redeveloped in dotNET. We are trying to decide if we should deploy using Webforms or Winforms and I need advice from...
5
by: Stan SR | last post by:
Hi, Some newbie questions.. :-) First, what is the namespace to use for the Cache class ? When I use this bit of code I get an error if (Cache==null) Cache.Insert("myUserList",userlist);...
8
by: Andrus | last post by:
I'm creating C# WinForms client-server database application. This application reads data from PostgreSQL server using npgsql Dataadapter and DataReader classes and stores data mostly in Datasets...
3
by: Gary W. Smith | last post by:
I had a couple questions about data caching. We have a site that gets a huge amount of traffic to a few specific pages that have a lot of data on them (300k hits/hour during peak, about 6-10 data...
4
by: Andrus | last post by:
For winforms application with multiple related forms it is reasonable to create Linq database context object in start of application. Context object is released only when application exits. So...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.