1 / 20

Caching MacDonald Ch. 26

Caching MacDonald Ch. 26. MIS 424 Professor Sandvig. Overview. What is Caching Where to cache When to cache Data caching in ASP.NET Page caching Page Fragment caching Cache Class Create you own cache. What is Caching. Cache = “secret store” Armies: cache weapons

media
Download Presentation

Caching MacDonald Ch. 26

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. CachingMacDonald Ch. 26 MIS 424 Professor Sandvig

  2. Overview • What is Caching • Where to cache • When to cache • Data caching in ASP.NET • Page caching • Page Fragment caching • Cache Class • Create you own cache

  3. What is Caching • Cache = “secret store” • Armies: cache weapons • Squirrels: cache nuts • Computers: cache data • Benefits of caching data: • Reuse • Process once, reuse many times • Faster, cheaper

  4. Where to Cache • Client-side • Browsers • Images • Pages • Reduces download times • Server-side • Reduces server processing load

  5. When to Cache on server • Frequently hit pages • Content changes infrequently • NYTimes.com • ESPN.com • CMS (see Drupal Boost) • Data is expensive to retrieve • MIS 424 • Weather forecast • Amazon Best Sellers

  6. When NOT to cache • Pages that change frequently • Shopping cart • Amazon.com • Customized for each user • Personal data • Infrequently accessed data • Cache must be stored  Overhead • cost depends upon caching method

  7. Caching Tools in ASP.NET • Caching Options • Page • Page fragment • Data class • Create your own • Database • Application or session object

  8. Page Caching • Caches entire page • Page directive: <%@ Page OutputCache Duration=“300” VaryByParm=“none” %> • Duration in seconds • Stored on disk • Low penalty

  9. Page Caching - parameters • VaryByParm= • “None” • Single cache for all parameter combinations • “*” • Different cache for each parameter combination • “ParameterList” • Different cache for listed parameters • One cache for other parameters

  10. Page Caching - parameters • Example: • 14_CachePage.aspx source, output • Location: • Server • Client • Downstream – proxy servers • Any • None

  11. Page Caching - parameters • Also may specify cache for header attributes: • Language • Browser version • Etc.

  12. ASP.NET Caching • Page • Page fragment • Data class • Create your own

  13. Page Fragment Caching • Cache part of a page • Content in user control • Syntax similar to Page cache • Example: • Music Store menu

  14. Page Fragment Caching • Benefits: • Useful for menus, headers, footers… • Easy to implement • Stored on disk • Weaknesses • OnClick events frozen • Timeout fixed duration only

  15. ASP.NET Caching • Page • Page fragment • Cache class • Create your own

  16. Cache Class • Cached data accessible throughout application • Use data on multiple page • Cache any type of data object • strings, datasets, dataviews, … • Set expiration date • Several options

  17. Cache Class • Cache.Insert method • Parameters for: • Expiration date – absolute & sliding • File dependencies • Database tables • Subroutine to run when expires • Documentation

  18. Cache Class - Syntax Cache.Add(Key, Object, CacheDependency, DateTime, TimeSpan, CacheItemPriority, CacheItemRemovedCallback) • Example: • CacheExample.aspx source, output

  19. Create Your Own • Program own rules • Customize storage location • Database • File • Combination of Cache locations • Expiration rule • Fixed time of day, week, month… • Number of hits… • Example: Weather forecast

  20. Summary • Several Caching options .NET • Page • Page fragment • Cache object • Roll your own • Dramatic performance improvements when data expensive to retrieve

More Related