Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. caching data on server in windows application in c#

caching data on server in windows application in c#

Scheduled Pinned Locked Moved C#
csharpcssdatabasecomsysadmin
12 Posts 7 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    siva455
    wrote on last edited by
    #1

    Hi, We have a windows app which is installed in many systems..and the server is resided on different PC..so whenever users loading the app due to many hits to server..the application is becoming very slow.. so i tried to use caching the data ..with expiration..(as we dont have any db changes during expiration time..) i tried the below article which was posted in codeproject... "http://www.codeproject.com/KB/cs/webservicecache.aspx" but this article explains to cache data locally..but i need o cache the data in the server...so that eventhough many users run the app the load will be less... Please help me regarding the same..

    S L P L P 6 Replies Last reply
    0
    • S siva455

      Hi, We have a windows app which is installed in many systems..and the server is resided on different PC..so whenever users loading the app due to many hits to server..the application is becoming very slow.. so i tried to use caching the data ..with expiration..(as we dont have any db changes during expiration time..) i tried the below article which was posted in codeproject... "http://www.codeproject.com/KB/cs/webservicecache.aspx" but this article explains to cache data locally..but i need o cache the data in the server...so that eventhough many users run the app the load will be less... Please help me regarding the same..

      S Offline
      S Offline
      Subin Mavunkal
      wrote on last edited by
      #2

      try some other techniques

      L 1 Reply Last reply
      0
      • S Subin Mavunkal

        try some other techniques

        L Offline
        L Offline
        Lost User
        wrote on last edited by
        #3

        Subin Mavunkal wrote:

        try some other techniques

        This is a really pointless answer and does nothing for CodeProject's reputation, and even less for yours.

        The best things in life are not things.

        1 Reply Last reply
        0
        • S siva455

          Hi, We have a windows app which is installed in many systems..and the server is resided on different PC..so whenever users loading the app due to many hits to server..the application is becoming very slow.. so i tried to use caching the data ..with expiration..(as we dont have any db changes during expiration time..) i tried the below article which was posted in codeproject... "http://www.codeproject.com/KB/cs/webservicecache.aspx" but this article explains to cache data locally..but i need o cache the data in the server...so that eventhough many users run the app the load will be less... Please help me regarding the same..

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          pradeep455 wrote:

          but this article explains to cache data locally..but i need o cache the data in the server...so that eventhough many users run the app the load will be less...

          That won't help much; database-servers are optimized to return data as fast as possible from their datastore. You'd still have the same amount of network-traffic, and the extra caching-application might consume CPU-time that the database-server wants, moving the delay from one application to another. Caching on the client side will remove the need to transport the data over the network and moves some work from the server to the local machine. That's the way to go, unless you have a server that never runs into capacity-problems. A simple way to achieve this is to synchronize the database from the server with a local copy. I'd only sync the readonly data; lookuplists do better when local, especially if required often. Or, if you have those in a real List, serialize them after retrieving them once, save it locally, and deserialize from the local path the next time your app starts.

          Bastard Programmer from Hell :suss:

          1 Reply Last reply
          0
          • S siva455

            Hi, We have a windows app which is installed in many systems..and the server is resided on different PC..so whenever users loading the app due to many hits to server..the application is becoming very slow.. so i tried to use caching the data ..with expiration..(as we dont have any db changes during expiration time..) i tried the below article which was posted in codeproject... "http://www.codeproject.com/KB/cs/webservicecache.aspx" but this article explains to cache data locally..but i need o cache the data in the server...so that eventhough many users run the app the load will be less... Please help me regarding the same..

            P Offline
            P Offline
            Pete OHanlon
            wrote on last edited by
            #5

            Let me get this right - you have a WinForms/WPF application that connects to a server to retrieve data and manipulate it. You want to retrieve information from the server and use it locally, but you think you will get better performance if you retrieve it from a cache at the server end. Have I understood your requirements properly? What I am unclear about here, is whether the remote machine is merely a database server, or whether it has web services that serve up the data. The client side architecture is greatly affected by this fact. If the remote PC is merely a database, then you should just retrieve the data and do any caching locally. It is possible that you are issuing slowdown problems because you are trying to run an enterprise database on a simple PC, and have other issues because of that design. If the remote PC is a web service (whether or not served up by WCF), then it could make sense to cache the data at the server side. Unfortunately, we cannot offer any more detailed help because you have not offered sufficient detail as to what your architecture actually is.

            Forgive your enemies - it messes with their heads

            My blog | My articles | MoXAML PowerToys | Mole 2010 - debugging made easier - my favourite utility

            S 1 Reply Last reply
            0
            • S siva455

              Hi, We have a windows app which is installed in many systems..and the server is resided on different PC..so whenever users loading the app due to many hits to server..the application is becoming very slow.. so i tried to use caching the data ..with expiration..(as we dont have any db changes during expiration time..) i tried the below article which was posted in codeproject... "http://www.codeproject.com/KB/cs/webservicecache.aspx" but this article explains to cache data locally..but i need o cache the data in the server...so that eventhough many users run the app the load will be less... Please help me regarding the same..

              L Offline
              L Offline
              Luc Pattyn
              wrote on last edited by
              #6

              pradeep455 wrote:

              installed in many systems.

              please define "many". does the app run fine when there is only one or two clients active? :)

              Luc Pattyn [My Articles] Nil Volentibus Arduum

              The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
              Please use <PRE> tags for code snippets, they improve readability.
              CP Vanity has been updated to V2.3

              1 Reply Last reply
              0
              • P Pete OHanlon

                Let me get this right - you have a WinForms/WPF application that connects to a server to retrieve data and manipulate it. You want to retrieve information from the server and use it locally, but you think you will get better performance if you retrieve it from a cache at the server end. Have I understood your requirements properly? What I am unclear about here, is whether the remote machine is merely a database server, or whether it has web services that serve up the data. The client side architecture is greatly affected by this fact. If the remote PC is merely a database, then you should just retrieve the data and do any caching locally. It is possible that you are issuing slowdown problems because you are trying to run an enterprise database on a simple PC, and have other issues because of that design. If the remote PC is a web service (whether or not served up by WCF), then it could make sense to cache the data at the server side. Unfortunately, we cannot offer any more detailed help because you have not offered sufficient detail as to what your architecture actually is.

                Forgive your enemies - it messes with their heads

                My blog | My articles | MoXAML PowerToys | Mole 2010 - debugging made easier - my favourite utility

                S Offline
                S Offline
                siva455
                wrote on last edited by
                #7

                Yes the remote PC is a webservice(serve up the data) ,and the clients are consuming the webservice.. and as u said(caching on server) if this is the case please let me know how to cache on the server..(in webservice)

                P 1 Reply Last reply
                0
                • S siva455

                  Yes the remote PC is a webservice(serve up the data) ,and the clients are consuming the webservice.. and as u said(caching on server) if this is the case please let me know how to cache on the server..(in webservice)

                  P Offline
                  P Offline
                  Pete OHanlon
                  wrote on last edited by
                  #8

                  You have hosted this in a web server then? If so, you simply need to use a pattern like this:

                  private MyData GetData()
                  {
                  HttpCache myCache = HttpContext.Current.Cache;
                  MyData data = myCache["MyData"];
                  if (data == null) return GetDataAndStoreInCache();
                  return data;
                  }

                  private MyData GetAndStoreInCache()
                  {
                  // Do something to get the data.
                  MyData data = RetrieveDataHere();
                  HttpContext.Current.Cache.Insert("MyData", data, null, DateTime.Now.AddHours(6), TimeSpan.Zero);
                  return data;
                  }

                  Forgive your enemies - it messes with their heads

                  My blog | My articles | MoXAML PowerToys | Mole 2010 - debugging made easier - my favourite utility

                  S 1 Reply Last reply
                  0
                  • S siva455

                    Hi, We have a windows app which is installed in many systems..and the server is resided on different PC..so whenever users loading the app due to many hits to server..the application is becoming very slow.. so i tried to use caching the data ..with expiration..(as we dont have any db changes during expiration time..) i tried the below article which was posted in codeproject... "http://www.codeproject.com/KB/cs/webservicecache.aspx" but this article explains to cache data locally..but i need o cache the data in the server...so that eventhough many users run the app the load will be less... Please help me regarding the same..

                    P Offline
                    P Offline
                    PIEBALDconsult
                    wrote on last edited by
                    #9

                    It depends on what the problem is. On a previous job, I had a number of clients (five or so, but could be more) that had to access the same data repeatedly (every minute or so) as they monitored the status of the running system. Because the data required a fair bit of calculation and aggregation I chose to have a Windows Service produce an XML file with the results that the clients could then download at their leisure. The Service ran on a fifteen-second cycle and produced one of ten files (e.g. SystemStatus.0.xml -- SystemStatus.9.xml) and when it was done it wrote the name of the latest file to the database for the clients to read.

                    1 Reply Last reply
                    0
                    • S siva455

                      Hi, We have a windows app which is installed in many systems..and the server is resided on different PC..so whenever users loading the app due to many hits to server..the application is becoming very slow.. so i tried to use caching the data ..with expiration..(as we dont have any db changes during expiration time..) i tried the below article which was posted in codeproject... "http://www.codeproject.com/KB/cs/webservicecache.aspx" but this article explains to cache data locally..but i need o cache the data in the server...so that eventhough many users run the app the load will be less... Please help me regarding the same..

                      J Offline
                      J Offline
                      jschell
                      wrote on last edited by
                      #10

                      pradeep455 wrote:

                      Please help me regarding the same..

                      First step is to actually determine what is causing the slow down. Attempting to guess bottlenecks is unlikely to be successful. Did you actually measure the time it took for various parts of your application and server?

                      1 Reply Last reply
                      0
                      • P Pete OHanlon

                        You have hosted this in a web server then? If so, you simply need to use a pattern like this:

                        private MyData GetData()
                        {
                        HttpCache myCache = HttpContext.Current.Cache;
                        MyData data = myCache["MyData"];
                        if (data == null) return GetDataAndStoreInCache();
                        return data;
                        }

                        private MyData GetAndStoreInCache()
                        {
                        // Do something to get the data.
                        MyData data = RetrieveDataHere();
                        HttpContext.Current.Cache.Insert("MyData", data, null, DateTime.Now.AddHours(6), TimeSpan.Zero);
                        return data;
                        }

                        Forgive your enemies - it messes with their heads

                        My blog | My articles | MoXAML PowerToys | Mole 2010 - debugging made easier - my favourite utility

                        S Offline
                        S Offline
                        siva455
                        wrote on last edited by
                        #11

                        Thanks for ur reply... i need to use this code snippet in webservice code right...? using HttpContext.Current.Cache instead of HttpRuntime.cache or Microsoft.ApplicationBlocks.cache is better? Correct me if im wrong..pls let me know which is better to use.. -- Modified Thursday, May 26, 2011 2:08 AM

                        P 1 Reply Last reply
                        0
                        • S siva455

                          Thanks for ur reply... i need to use this code snippet in webservice code right...? using HttpContext.Current.Cache instead of HttpRuntime.cache or Microsoft.ApplicationBlocks.cache is better? Correct me if im wrong..pls let me know which is better to use.. -- Modified Thursday, May 26, 2011 2:08 AM

                          P Offline
                          P Offline
                          Pete OHanlon
                          wrote on last edited by
                          #12

                          You would be OK using HttpRuntime.Cache. Basically, HttpContext.Current.Cache is a version of HttpRuntime.Cache. In fact, all that HttpContext.Current.Cache really does is pass the request onto HttpRuntime.Cache (the big difference being that HttpRuntime.Cache is available for all cases, so you can even use it in a console application if you want). My sample wasn't meant to be used literally, rather it was to demonstrate some possible techniques. As it stands, it's not a totally robust situation as you could enter a situation where between the time of the lookup and the insert into the cache, another process inserts the data into the cache. If you code this robustly, you need to take this into account.

                          Forgive your enemies - it messes with their heads

                          My blog | My articles | MoXAML PowerToys | Mole 2010 - debugging made easier - my favourite utility

                          1 Reply Last reply
                          0
                          Reply
                          • Reply as topic
                          Log in to reply
                          • Oldest to Newest
                          • Newest to Oldest
                          • Most Votes


                          • Login

                          • Don't have an account? Register

                          • Login or register to search.
                          • First post
                            Last post
                          0
                          • Categories
                          • Recent
                          • Tags
                          • Popular
                          • World
                          • Users
                          • Groups