persistent cache in SQL Server

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Trapulo

    persistent cache in SQL Server

    Hello,
    I'm developing an asp.net application that is connected to a remote system
    using WCF (wshttp binding). So I want to use a local cache to manage data
    that I receive from remote service.

    I'm using caching block from MS application enterprise library 4.1,
    configured to use a SQL Server cache. That's great: it works with very
    little effort.
    However I noticed that caching block mantains a copy of the cache in memory
    (loading all cache when it starts). I want to matain data only in SQL
    Server, because are very large data that I mantain in cache for a lot of
    time (about 7 days). Is there any way I can use ONLY the SQL Server
    repository instead of in.memory AND Sql Server?

    thanks




  • Gregory A. Beamer

    #2
    Re: persistent cache in SQL Server

    The idea behind cache, as MS has it, is to save time getting information by
    putting it in memory. SQL is there as a backup, but it is not designed to be
    a primary mechanism, as SQL retrievals are slower than memory. If you want
    to store long term temporary infomration in SQL and not really cache,
    consider rolling your own mechanism rather than use the MS cache bits, as
    you are not really caching here.

    --
    Gregory A. Beamer
    MVP: MCP: +I, SE, SD, DBA

    Blog:


    *************** *************** **************
    | Think Outside the Box! |
    *************** *************** **************
    "Trapulo" <trapulo2@noema il.noemailwrote in message
    news:DFC6D3B3-0E83-45BA-B002-AD4DA5D0F101@mi crosoft.com...
    Hello,
    I'm developing an asp.net application that is connected to a remote system
    using WCF (wshttp binding). So I want to use a local cache to manage data
    that I receive from remote service.
    >
    I'm using caching block from MS application enterprise library 4.1,
    configured to use a SQL Server cache. That's great: it works with very
    little effort.
    However I noticed that caching block mantains a copy of the cache in
    memory (loading all cache when it starts). I want to matain data only in
    SQL Server, because are very large data that I mantain in cache for a lot
    of time (about 7 days). Is there any way I can use ONLY the SQL Server
    repository instead of in.memory AND Sql Server?
    >
    thanks
    >
    >
    >
    >

    Comment

    • Trapulo

      #3
      Re: persistent cache in SQL Server

      Yes: I need a cache that saves time getting data from remote WCF Server,
      instead of saving data from getting data from SQL Server. So SQL is a lot
      faster that a remote WCF call and I need a "real cache"...

      Is there some ready library I can use someone can suggest? I not want to
      write my own code to have a very common scenario...

      thanks



      "Gregory A. Beamer" <NoSpamMgbworld @comcast.netNoS pamMwrote in message
      news:uP19wqyRJH A.5860@TK2MSFTN GP02.phx.gbl...
      The idea behind cache, as MS has it, is to save time getting information
      by putting it in memory. SQL is there as a backup, but it is not designed
      to be a primary mechanism, as SQL retrievals are slower than memory. If
      you want to store long term temporary infomration in SQL and not really
      cache, consider rolling your own mechanism rather than use the MS cache
      bits, as you are not really caching here.
      >
      --
      Gregory A. Beamer
      MVP: MCP: +I, SE, SD, DBA
      >
      Blog:

      >
      *************** *************** **************
      | Think Outside the Box! |
      *************** *************** **************
      "Trapulo" <trapulo2@noema il.noemailwrote in message
      news:DFC6D3B3-0E83-45BA-B002-AD4DA5D0F101@mi crosoft.com...
      >Hello,
      >I'm developing an asp.net application that is connected to a remote
      >system using WCF (wshttp binding). So I want to use a local cache to
      >manage data that I receive from remote service.
      >>
      >I'm using caching block from MS application enterprise library 4.1,
      >configured to use a SQL Server cache. That's great: it works with very
      >little effort.
      >However I noticed that caching block mantains a copy of the cache in
      >memory (loading all cache when it starts). I want to matain data only in
      >SQL Server, because are very large data that I mantain in cache for a lot
      >of time (about 7 days). Is there any way I can use ONLY the SQL Server
      >repository instead of in.memory AND Sql Server?
      >>
      >thanks
      >>
      >>
      >>
      >>
      >

      Comment

      • Allen Chen [MSFT]

        #4
        Re: persistent cache in SQL Server

        Hi Trapulo,

        From your description you want to store the data into SQL Server that is
        retrieved from WCF, right? If so, as Gregory said, it's not a cache.

        First I need to confirm if you need a global data structure or a
        user-independent data structure. If the data is user independent I suggest
        you use the ASP.NET Session. As we know, session can be stored in SQL
        Server:



        You can call WCF method and store the retrieved data into Session.
        If it's global data you can design a table:

        Key P.K.
        Value
        TimeStamp

        Then store the retrieved data into database and use Sql Server Agent
        Service to remove the expired records every 7 days.

        Please let me know if you have any questions.

        Regards,
        Allen Chen
        Microsoft Online Support

        Delighting our customers is our #1 priority. We welcome your comments and
        suggestions about how we can improve the support we provide to you. Please
        feel free to let my manager know what you think of the level of service
        provided. You can send feedback directly to my manager at:
        msdnmg@microsof t.com.

        =============== =============== =============== =====
        Get notification to my posts through email? Please refer to
        http://msdn.microsoft.com/en-us/subs...#notifications.

        Note: MSDN Managed Newsgroup support offering is for non-urgent issues
        where an initial response from the community or a Microsoft Support
        Engineer within 2 business day is acceptable. Please note that each follow
        up response may take approximately 2 business days as the support
        professional working with you may need further investigation to reach the
        most efficient resolution. The offering is not appropriate for situations
        that require urgent, real-time or phone-based interactions. Issues of this
        nature are best handled working with a dedicated Microsoft Support Engineer
        by contacting Microsoft Customer Support Services (CSS) at

        =============== =============== =============== =====
        This posting is provided "AS IS" with no warranties, and confers no rights.

        Comment

        • Trapulo

          #5
          Re: persistent cache in SQL Server

          "Allen Chen [MSFT]" <v-alchen@online.m icrosoft.comwro te in message
          news:qxsUqXSSJH A.4804@TK2MSFTN GHUB02.phx.gbl. ..
          Hi Trapulo,
          >
          From your description you want to store the data into SQL Server that is
          retrieved from WCF, right? If so, as Gregory said, it's not a cache.
          Yes
          However I think it's sure a cache


          "In computer science, a cache (pronounced /kæʃ/) is a collection of data
          duplicating original values stored elsewhere or computed earlier, where the
          original data is expensive to fetch (owing to longer access time) or to
          compute, compared to the cost of reading the cache"
          First I need to confirm if you need a global data structure or a
          user-independent data structure
          global data.
          If the data is user independent I suggest
          you use the ASP.NET Session. As we know, session can be stored in SQL
          Server:
          >

          >
          >You can call WCF method and store the retrieved data into Session.
          this can be interesting. However, as I said, data are global
          If it's global data you can design a table:
          >
          Key P.K.
          Value
          TimeStamp
          >
          Then store the retrieved data into database and use Sql Server Agent
          Service to remove the expired records every 7 days.
          >
          Please let me know if you have any questions.
          Ok thanks.
          I was hoping to find a full featured complete library (as logging block).
          In fact, however, it can be good to have a copy either in memory and sql
          server. But logging block retains in memory all data. If it can retain, for
          example, last 100 objects in memory, and 10000 in sql, it will be great (100
          is too little to my requirenments, an 10000 is to big to leave in memory).
          Instead of this, it has just a single parameter that sets memory and sql
          cache. Is there any easy way we can extend logging block to have this goal?

          thanks





          Comment

          • Allen Chen [MSFT]

            #6
            Re: persistent cache in SQL Server

            Hi Trapulo,

            Quote from Trapulo =============== =============== =============== ====
            In fact, however, it can be good to have a copy either in memory and sql
            server. But logging block retains in memory all data. If it can retain, for
            example, last 100 objects in memory, and 10000 in sql, it will be great
            (100
            is too little to my requirenments, an 10000 is to big to leave in memory).
            Instead of this, it has just a single parameter that sets memory and sql
            cache.
            =============== =============== =============== ====

            As far as I know currently the enterprise library does not provide that
            flexibility. The SQL data storage for the caching block is mainly used to
            backup cached data in case in-memory cache is lost due to application
            crash. It's not proposed as a primary cache.

            To achieve your requirement we can write our own cache mechanism. The
            pseudocode may be:

            using System.Web.Cach ing;

            public class MyCacheManager
            {
            private static Cache _cache = new Cache();
            public static void AddCache(object data,object key)
            {

            if (_cache.Count 100)
            {
            //insert data to database
            }
            else
            {
            //add data to _cache
            //optional, add a copy to database in case in-memory cache
            is lost.
            }


            }
            public static object GetCache(object key)
            {
            //if the data retrieved from _cache is null, access database
            //if still no record retrieved, return null.
            }

            }

            We can design a table to store the data and use SQL Server agent to remove
            records every 7 days.

            You can also consider using distributed caching. Though it's not the means
            as you thought above it's another option that can increase performance.


            If you have further questions please feel free to ask.

            Regards,
            Allen Chen
            Microsoft Online Community Support

            Comment

            Working...