ASP.NET 2.0 Caching and Data Binding - PowerPoint PPT Presentation

1 / 25
About This Presentation
Title:

ASP.NET 2.0 Caching and Data Binding

Description:

To offer assistance and resources to community groups that promote and educate ... Helping groups get organized for a more sustainable group ... – PowerPoint PPT presentation

Number of Views:444
Avg rating:3.0/5.0
Slides: 26
Provided by: Jos169
Category:
Tags: asp | net | artemis | binding | caching | data

less

Transcript and Presenter's Notes

Title: ASP.NET 2.0 Caching and Data Binding


1
ASP.NET 2.0 Caching and Data Binding
  • Josh Holmes

2
About Josh Holmes
  • Consultant/Trainer/Mentor
  • Principal in SRT Solutions
  • Great Lakes Area .NET Users Group
  • Vice President
  • Program Chair
  • Ann Arbor Computer Society
  • President
  • INETA Speaker
  • Microsoft MVP
  • http//www.srtsolutions.com
  • jholmes_at_srtsolutions.com

3
About International .NET Association (INETA)
  • http//www.ineta.org
  • Mission
  • To offer assistance and resources to community
    groups that promote and educate their membership
    in Microsoft's .NET technologies
  • Organizational For user group leaders and
    officers
  • Helping groups get organized for a more
    sustainable group
  • Educational Supporting the core need of user
    groups
  • Presentation repository with content from both
    sponsor companies and other user groups
  • Speakers Bureau will provide groups with
    opportunities to attract marquee speakers and
    noted .NET authors from around the country
  • Promotional Building the membership
  • Searchable, international user group directory
  • Promote user groups at major .NET events

4
Agenda
  • What is Data Binding?
  • What are the new Data Binding features in ASP.NET
    2.0?
  • What is Cache?
  • What are the Caching features in ASP.NET 2.0?
  • How to leverage the two together...

5
What is Data Binding?
  • Using Data Bound controls to generate the HTML
    rather than writing the HTML yourself
  • Everything from Calendar to TextBoxes can be data
    bound
  • Major Data bound controls
  • DataGrid (ASP.NET 1.0/1.1)
  • GridView (ASP.NET 2.0)
  • DetailsView (ASP.NET 2.0

6
ASP.NET 1.1 Databinding
  • Steps to data binding
  • Pull data
  • Create the data bound controls
  • Assign the Data Source to the newly pulled data
    (often a dataset, but could be an object)
  • Use Property Pane and/or ASP.NET 1.1 data binding
    syntax to pull property

lt DataBinder.Eval(Container.DataItem,
"PropertyName") gt
7
ASP.NET 2.0 Binding
  • Steps to data binding
  • Pick a data source
  • Pick display format
  • Drag data source onto form
  • Possibly use ASP.NET 2.0 data binding syntax to
    edit
  • More on next slide

8
ASP.NET 2.0 Binding cont.
  • Old form still works
  • Two new forms
  • Nonhierarchical data binding
  • Hierarchical (I.E. XML)

lt Eval("PropertyName") gt
lt XPath(XPath Statement") gt
9
New GridView Control
  • Similar to DataGrid
  • Sorts and pages with no code
  • Also sizes for phones and other devices with no
    extra code
  • Can have no code data editing
  • Using two way bindings
  • Bind instead of Eval

10
More new controls
  • Details View
  • Mostly for use with a GridView
  • Provides detail view for one of the master rows
    in a sub-grid
  • Form View
  • Similar to the previous control except that it is
    all templated rather than a grid style layout
  • Similar to the Data Repeater from 1.x

11
Data Source Controls
  • Replaces majority of data access code written in
    ASP.NET 1.x
  • SqlDataSource
  • AccessDataSource
  • DataSetDataSource
  • XmlDataSource
  • Can select data, specify how to edit data and more

12
What is Cache?
  • Per Application on a Machine store of memory
  • Two kinds Data Cache and Page Cache
  • Data Cache allows caching of any .NET object
  • Often used to limit trips to database but still
    give dynamic look and feel to web site
  • Page Cache allows caching of an ASPX or ASCX
  • Used to produce high performance but seldom
    changing pages

13
Page Caching
  • Caches the rendered output
  • Savings
  • Processing time
  • Data access time
  • Can be set up administratively after the app is
    deployed
  • Can be used on just a user control
  • Can be parameterized

14
How to Page Cache
  • Page caching is administered through the
    OutputCache directive in the page
  • Next to PageDirective

lt_at_ OutputCache Duration"ofseconds"
Location"Any Client Downstream Server
None" Shared"True False" VaryByControl"contr
olname" VaryByCustom"browser customstring"
VaryByHeader"headers" VaryByParam"parameternam
e" gt
15
Data Caching
  • Compare to Application storage
  • Not cross machine
  • Much better in many situations with cache
    invalidation and timeouts
  • Caches any .NET object
  • Does not save rendered HTML
  • Savings
  • Data access time
  • Often used to cache datasets

16
How to Data Cache
  • Insert an object into the Cache object
  • Stored in memory on this machine/application
  • Stored until server sees fit to remove it or
    restart of application

string t Cache"TimeString" as string if (t
null) t DateTime.Now.ToString()
Cache.Insert("TimeString", t) _lblTime.Text
t
17
How to Data Cache Cont
  • Adding Timeouts
  • Set the TimeSpan to Zero and the timeout to an
    absolute time
  • Set the absolute time to MaxValue and the
    TimeSpan to some number of seconds
  • Adding Dependency
  • One Type in v1.1 and its a File Dependency

CacheDependency d new CacheDependency(_at_"c\test.
xml") Cache.Insert("TimeString", t, d,
DateTime.MaxValue, TimeSpan.FromSeconds(10),)
18
Data Cache Removal Callbacks
  • Receive a delegate callback when an object is
    removed from cache

public void RemovedCallback(string key, object o,
CacheItemRemovedReason reason) //Do nothing
at the moment
Cache.Insert("TimeString", t, d,
DateTime.MaxValue, TimeSpan.FromSeconds(10),
System.Web.Caching.CacheItemPriority.Normal,
new CacheItemRemovedCallback(this.RemovedCallbac
k))
19
V2.0 Caching Features
  • Single biggest is that CacheDependency is not
    sealed
  • Can create custom dependencies or use
    SQLCacheDependency

20
Why is it important?
  • Imagine Cache Dependencies on
  • MSMQ
  • RSS
  • A web service
  • Active Directory

21
SQL Cache Dependency
  • 3 things have to be setup
  • SQL Server
  • Run utility or wait for SQL Server 2005
  • Application
  • Web.Config
  • Your Code
  • Could be declaratively through the OutputCache
    directive
  • Could be in code

22
SQL Cache Dependency Config
ltcachinggt ltsqlCacheDependency enabled"true"
pollTime"1000"gt ltdatabasesgt ltadd
name"Northwind connectionStringName"NorthwindC
onnectionString1"/gt lt/databasesgt lt/sqlCacheDepe
ndencygt lt/cachinggt
23
ASPNET_REGSQL utility
  • -S server
  • -E trusted connection
  • Could use U and P for user and password
  • -t table to enable for notification
  • -d database
  • -et enable triggers

24
Output Cache Replacements
  • Allows substitution of one small area in the
    prerendered HTML output
  • Use an aspsubstitution
  • Provide a method for the call back

25
ASP.NET 2.0 Caching and DataBinding
  • Josh Holmes
Write a Comment
User Comments (0)
About PowerShow.com