Download presentation
Presentation is loading. Please wait.
Published byMichael Harrell Modified over 9 years ago
1
Caching MacDonald Ch. 26 MIS 424 MIS 424 Professor Sandvig Professor Sandvig
2
Overview What is Caching Where to cache When to cache Data caching in ASP.NET 1.Page caching 2.Page Fragment caching 3.Cache Class Create you own cache
3
What is Caching Cache = “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 ImagesPages –Reduces download times Server-side –Reduces server processing load
5
When to Cache on server Frequently hit pages –Content changes infrequently NYTimes.comESPN.com CMS (see Drupal Boost) 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 Infrequently accessed data –Cache must be stored Overhead –cost depends upon caching method
7
Caching Tools in ASP.NET Caching Options 1.Page 2.Page fragment 3.Data class 4.Create your own Database Database Application or session object Application or session object
8
Page Caching Caches entire page Page directive: –Duration in seconds Stored on disk –Low overhead
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 –14_CachePage.aspx source, output sourceoutputsourceoutputLocation: –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 1. Page 2. Page fragment 3. Data class 4. 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 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 1. Page 2. Page fragment 3. Cache class 4. 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 sourceoutputsourceoutput
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
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.