Cache vs Session, Application state for datagrid

Discussion in 'ASP .Net Datagrid Control' started by marina.sukhnev, Mar 2, 2006.

  1. Hi Guys,

    I have a question,what is the best way to preserve dataset in web
    application:
    Cache object,Session or Application state.
    Any ideas?

    Thanks,

    Marina
     
    marina.sukhnev, Mar 2, 2006
    #1
    1. Advertisements

  2. marina.sukhnev

    Elton Wang Guest

    Hi Marina,

    First of all, let's see the difference between SessionState and
    ApplicationState. When you store data in Session, it is only available for
    one user Session (even when a user open a new browser by clicking desktop
    icon or Start -> Programs -> browser menu in same computer, it starts a new
    Session.) On the other hand, data in ApplicationState can be accessed cross
    sessions in the application. Hence, if you want the data to be shared for
    different users, use Application, otherwise use Session.

    Secondly, let's see Cache. It has the same scope as Application. And it also
    has some other feathers, such as, CacheDependency (e.g. some file or files),
    expiry date time, time span, and so on.

    Thirdly, advantages of using them are good performance (it cuts
    communication between web server and database) and sharing data cross pages.
    Disadvantages are consuming web server memory resource (when in user and
    data intensive application, it causes server dead soon) and out of time data
    (so you might need some refresh events).

    HTH
     
    Elton Wang, Mar 2, 2006
    #2
    1. Advertisements

  3. marina.sukhnev

    Marisha Guest

    Thank you Elton for quick response,

    I was testing Session and Cache objects with my dataset,that bound to
    datagrid,when I load some item that has 950 rows and try to do some
    operations like edit,delete,update,very soon I'm getting Out of Memory
    Exception,means server crushes,till I reset IIS.
    Which refresh events did you mean?
    Do you have some suggestions,is 950 rows too much to handle?

    Thanks a lot,

    Marina
     
    Marisha, Mar 2, 2006
    #3
  4. marina.sukhnev

    Elton Wang Guest

    Normally, it should handle much more than 900 rows data.



    However, from user perspective, do you think it is good idea to edit 900
    rows of data in one page?



    To be able to refresh the cache data based on the fact that someone else has
    changed a row in the database. Programmers have resorted to a few different
    techniques to accomplish this, such as writing a trigger that updates a file
    when the table or view changes, or refreshing the cache every so often
    whether the database has changed or not. There is no straightforward way the
    register for database notifications until the SqlClient
    SqlNotificationRequest and SqlDependency classes in ADO.NET 2.0.



    HTH
     
    Elton Wang, Mar 2, 2006
    #4
  5. marina.sukhnev

    Marisha Guest

    Elton,
    User edits only couple rows out of 900 and it is a radical example,in
    most cases the grid has 20-50 rows of data,then it is not a problem.
    But i have couple items that have bulky data such as 500+ items and
    only there the problem occurs.I refresh my cache every time i
    add,delete,update some records of the grid,but it doesn't help.
    I tried it on two servers and both of them throw the same exception .

    Marina
     
    Marisha, Mar 2, 2006
    #5
  6. marina.sukhnev

    Marisha Guest

    Elton,
    User edits only couple rows out of 900 and it is a radical example,in
    most cases the grid has 20-50 rows of data,then it is not a problem.
    But i have couple items that have bulky data such as 500+ items and
    only there the problem occurs.I refresh my cache every time i
    add,delete,update some records of the grid,but it doesn't help.
    I tried it on two servers and both of them throw the same exception .

    Marina
     
    Marisha, Mar 2, 2006
    #6
  7. marina.sukhnev

    Elton Wang Guest

    How many columns in each row?
     
    Elton Wang, Mar 2, 2006
    #7
  8. marina.sukhnev

    Marisha Guest

    Elton,
    User edits only couple rows out of 900 and it is a radical example,in
    most cases the grid has 20-50 rows of data,then it is not a problem.
    But i have couple items that have bulky data such as 500+ items and
    only there the problem occurs.I refresh my cache every time i
    add,delete,update some records of the grid,but it doesn't help.
    I tried it on two servers and both of them throw the same exception .

    Marina
     
    Marisha, Mar 2, 2006
    #8
  9. marina.sukhnev

    Marisha Guest

    about 15-18 columns.Most of the time 15
     
    Marisha, Mar 3, 2006
    #9
  10. marina.sukhnev

    Elton Wang Guest

    How about to use ViewState to save dataset? In your worst scenario, if it's
    900 rows, datagrid viewstate is about 1.5 mb. DataSet occupies about 1 mb in
    viewstate. So totally about 2.5 mb.
     
    Elton Wang, Mar 3, 2006
    #10
  11. marina.sukhnev

    Marisha Guest

    Oh,I'm over it already.
    I used ViewState,and then the page won't load at all,it will hang even
    for 50-70 rows in datagrid.
    When I realized that I can use Cache object or session state,I thought
    all my problems are resolved,but apparently I still have them with
    bulky data in datagrid...
     
    Marisha, Mar 3, 2006
    #11
  12. marina.sukhnev

    Elton Wang Guest

    If traffic between Web server and Database server is not very busy, try
    directly query data from database every time. And using paging (in datagrid
    and from stored procedure) to limit data amount.
     
    Elton Wang, Mar 3, 2006
    #12
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.