private function loaddataset() as dataset dim sqlconnection as sqlconnection dim sqladapater as sqldatasetcommand dim datasetproducts as new dataset() dim sqldsn as string dim sqlselect as string
" connection string and select statement sqldsn = "server=localhost;uid=sa;pwd=;database=grocertogo" sqlselect = "select * from products"
" connect sqlconnection = new sqlconnection(sqldsn) sqladapater = new sqldatasetcommand(sqlselect, sqlconnection)
" fill dataset create product table sqladapter1.filldataset(datasetproducts, "products")
return products end function 我们很容易用cache对象来改写这段代码,使只在dataset不存在在cache中才调用loaddataset()。
public function getproductdata() as dataset if (isnothing(cache("productdata")) then cache("productdata") = loaddataset()
return cache("productdata") end function cache对象在许多地方和application对象有许多相似之处,而最大的不同是cache支持了依赖。