Scope of the Cache Object


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 4 of 4

Thread: Scope of the Cache Object

  1. #1
    michael Guest

    Scope of the Cache Object


    I know you can get and set Cache items from aspx pages but how do you obtain
    a reference to the Cache object in the business or data layer classes. I
    am attempting to Cache Dataset in memory of lists tables.

    e.g.
    -- Web Page
    Protected Sub PopulateDropDowns()
    dim db as new MyNamespace.DataLayer.Lists
    ddlProducts.Datasource = db.GetDropDownList(Products)
    ...
    End Sub

    -DataLayer (MyNamespace.DataLayer.Lists class)
    Public Function GetDropDownList(ListType as ListTypes) As DataView
    Dim ds as DataSet

    ds = Cache(ListType) 'CACHE OBJECT IS NOT AVAILABLE IN THIS
    If ds Is Nothing Then 'NAMESPACE/CLASS
    'Get New List from Database
    ds = GetList(ListType)
    'Add the new list to cache
    If not DS is Nothing then Cache.Insert(ListType, ds)
    End If

    If Not ds Is Nothing Then Return ds.Tables(0).DefaultView

    End Function

    I've even tried to Imports System.Web.Caching and still doesn't work.
    I also tried the following but it doesn't store is in cache but in another
    area. It does not have any dependecy options anyway.
    Dim c As System.AppDomain
    c.CurrentDomain.SetData(Name, Data)

    Do I need to pass as reference of the Cache object to the Business & Data
    Layers in the constructor?

    Any help would be much appreciated.

    Thanks
    michael


  2. #2
    Phil Weber Guest

    Re: Scope of the Cache Object

    > Do I need to pass as reference of the Cache object
    > to the Business & Data Layers in the constructor?


    Michael: That would work. You might also try "HttpContext.Current.Cache"
    instead of just "Cache".
    --
    Phil Weber


  3. #3
    mcihael Guest

    Re: Scope of the Cache Object


    Thanks Phil

    "Phil Weber" <philweber@hotmail.com> wrote:
    > > Do I need to pass as reference of the Cache object
    > > to the Business & Data Layers in the constructor?

    >
    >Michael: That would work. You might also try "HttpContext.Current.Cache"
    >instead of just "Cache".
    >--
    >Phil Weber
    >



  4. #4
    Testo Guest

    Re: Scope of the Cache Object


    Firstly,

    Import System.Web

    Then,

    add this to Cache in your BAL, DAL

    HttpContext.Current.Cache instead of just Cache

    Hope it helps

    "michael" <mmayfield_NOSPAM@houston.rr.com> wrote:
    >
    >I know you can get and set Cache items from aspx pages but how do you obtain
    >a reference to the Cache object in the business or data layer classes. I
    >am attempting to Cache Dataset in memory of lists tables.
    >
    >e.g.
    >-- Web Page
    >Protected Sub PopulateDropDowns()
    > dim db as new MyNamespace.DataLayer.Lists
    > ddlProducts.Datasource = db.GetDropDownList(Products)
    > ...
    >End Sub
    >
    >-DataLayer (MyNamespace.DataLayer.Lists class)
    >Public Function GetDropDownList(ListType as ListTypes) As DataView
    > Dim ds as DataSet
    >
    > ds = Cache(ListType) 'CACHE OBJECT IS NOT AVAILABLE IN THIS
    > If ds Is Nothing Then 'NAMESPACE/CLASS
    > 'Get New List from Database
    > ds = GetList(ListType)
    > 'Add the new list to cache
    > If not DS is Nothing then Cache.Insert(ListType, ds)
    > End If
    >
    > If Not ds Is Nothing Then Return ds.Tables(0).DefaultView
    >
    >End Function
    >
    >I've even tried to Imports System.Web.Caching and still doesn't work.
    >I also tried the following but it doesn't store is in cache but in another
    >area. It does not have any dependecy options anyway.
    > Dim c As System.AppDomain
    > c.CurrentDomain.SetData(Name, Data)
    >
    >Do I need to pass as reference of the Cache object to the Business & Data
    >Layers in the constructor?
    >
    >Any help would be much appreciated.
    >
    >Thanks
    >michael
    >



Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center