Plip already
let the cat out of the bag, but I feel obliged to blog about Spang as well. Sadly, beyond the name, we aren't allowed to share any more, but if you're a web developer you should expect to hear more about it "soon".
I'm nearly finished with my cache wrapper object, which I've named SuperCache for lack of a better name (Cache being taken, naturally). I'll be releasing it with source and a small article describing how to use it, most likely on ASPAlliance.com, but before I call it done I want to solicit some feedback and see if there are any features people are interested in that I could add in.
Currently it wraps pretty much all of the interesting methods of the existing System.Web.Caching.Cache object, as well as adding the following:
- Clear() - removes all entries from the cache
- RemoveByPattern() - removes all entries whose keys match a given regular expression
- InsertRenewable() - inserts an item and specifies a callback method to use to update the item periodically using a background thread. The user always gets a cached value (fast access), but that value is never stale (at least, no more stale than the interval specified).
- Insert() and Add() - I support the use of both sliding and absolute expirations concurrently. This allows for scenarios like "keep cached as long as the item has been requested in the last minute, but not any longer than one hour" which are not supported (easily) using the standard Cache object.
The main reason why you would use this object is to abstract your dependency on a framework object so that if/when you need to extend it or swap it out, you can easily do so. That is why this will be released with source, and you will be encouraged to add it to your own class library as something like MyCompany.Framework.Caching.SuperCache. Additionally, I hope the extra functionality I'm exposing will be useful in some situations.
I've posted up a new photo gallery for
MVP-Insiders Summit 2005 pictures, which I'll be updating as the week goes on. The next few days we'll be meeting with the ASP.NET team to discuss upcoming enhancements to web applications using Microsoft technologies. (
more on ASPInsiders).
VSTS originally used intuitive colors for code that was covered, code that was not covered, and code that was partially covered. In beta 2, these was changed to a bunch of pastel colors, as others like Dave Donaldson notes. Dave explains how to switch this back to the more obvious primary colors:
To do this, go to Tools, Options, Environment, Fonts and Colors. Under the Display Items list, look for Coverage Not Touched Area, Coverage Partially Touched Area, and Coverage Touched Area. Then change the Item Background color for each of those as you see fit.
You may know that I'm a big fan of caching. My latest pet project is the creation of a cache wrapper object that extends the capabilities of the standards HttpRuntime.Cache (or System.Web.Caching.Cache) object. One feature that I'm implementing is capability to insert an entry into the Cache and specify both a sliding and an absolute expiration. This scenario is not supported using the standard .NET Framework Cache object (and this will not change in 2.0), but it is a useful scenario because in a busy site a sliding expiration may never expire. The basic idea I'm going for is "As long as this resource is being actively requested (which we'll define as having been requested in the last 10 seconds), keep it in the cache, but only keep it cache at most for 10 minutes." You can get round this using the standard cache mechanism by adding a key dependency on another cache item that has the absolute|sliding expiration you need in addition to the sliding|absolute expiration you add to the 'real' cache entry.
Ok, so on to the 'Feature' that is the subject of this post. In the course of testing my cache wrapper object (which I will publish when it's a bit closer to ready, and will almost certainly show off at my upcoming user group and ASPConnections cache talks), I created a test for sliding expiration in my suite of unit tests. Since this was a unit test, I wanted it to run fast, so I set the sliding expiration to just one second and tried accessing it at 200 millisecond intervals to confirm that it worked. It didn't, oddly enough. The stranger thing is that switching to a SlidingExpirationTimeSpan > 1 second fixes the problem. So, this is hardly a show-stopper issue, but it is interesting and I'm going to code around it in my wrapper.
If you'd like to repro this behavior, compile and run this little command line application:
using
System;
namespace
ConsoleApplication1
{
/// <summary>
/// Summary description for Class1.
/// </summary>
class Class1
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main(string[] args)
{
string myKey = "foo";
string myValue = "bar";
int cacheSeconds = 1;
System.Web.HttpRuntime.Cache.Insert(myKey, myValue,
null, DateTime.MaxValue,
TimeSpan.FromSeconds(cacheSeconds), System.Web.Caching.CacheItemPriority.NotRemovable,
null);
if(!myValue.Equals(System.Web.HttpRuntime.Cache[myKey]))
{
Console.WriteLine("Cached value after Insert does not match stored object.");
}
for (int i = 1; i <= 20; i++) // read the cache 20 times at 200ms intervals
{
int msToSleep = 200;
System.Threading.Thread.Sleep(msToSleep);
if(!myValue.Equals(System.Web.HttpRuntime.Cache[myKey]))
{
Console.WriteLine("Cached value does not match stored object after " + i * msToSleep + " ms.");
break;
}
else
{
Console.WriteLine("Cached value still valid after " + i * msToSleep + " ms.");
}
}
System.Threading.Thread.Sleep(cacheSeconds + 100);
if(System.Web.HttpRuntime.Cache[myKey] !=null)
{
Console.WriteLine("Cached should have expired (sliding expiration has elapsed).");
}
Console.ReadLine();
}
}
}
You should get this result:

So, I'm in Seattle for the MVP Summit and it is a great time to network with a lot of people I haven't seen in quite some time (and many I just saw a couple of weeks ago at PDC...). They've been having some issues with transportation, so for instance yesterday morning about 100 of us ended up missing the first executive session altogether and half of Steve Ballmer's presentation because our bus was nearly an hour late picking us up from our downtown hotel. Oh well, what can you do. As usual it's an honor to have the time with Microsoft executives that they give to MVPs every year. Sadly, there were a few MVPs who, in my opinion, abused the privilege of being able to ask direct questions to these executives by behaving disrespectfully toward them, but perhaps that's just me.
I met up with a bunch of people in the last couple of days, but in particular Donny Mack requested I blog about him. He's got a pretty sweet M3 that I drove from Bellevue to Seattle last night, and he was kind enough to buy a round of drinks in honor of my Army service last night. So, here's to you Donny, thanks. :)
I just completed the ASP.NET “Atlas” hands-on lab. It was very well put-together considering how completely new Atlas is. I imagine a few members of the ASP.NET team probably lost some sleep the week prior to PDC getting all of this put together in time. You can complete the lab yourself -- it's available from the Atlas website. At the moment it requires the Beta 2 version of ASP.NET, but a new lab targeting the RC build of .NET 2.0 should be available very soon.
The lab has 5 parts and shows you first how to set up a master page to hold your Atlas script library references, then quickly moves into useful examples. You learn how to use asynchronous callbacks to web services to set the value of a label (without a postback, naturally) using a bit of javascript. Then again, using a new declarative tag model that is unique to Atlas's approach (as opposed to, say, AJAX.Net) and parallels the ASP.NET server control syntax. The next lab further encapsulates things by using Atlas server controls, which remove the need for the developer to write any client side code. You'll create an auto-completion textbox which is pretty slick, and finally the lab wraps up with a no-code, templated, databound listview which is populated via callbacks.
Considering how new ASP.NET “Atlas” is, it's very impressive. I spoke with one of the Microsofties on the Atlas team, and he explained that one of their goals was to make the whole architecture for this kind of thing easier, as opposed to just creating another library allowing XML-HTTP calls back to the server. To that end, they're encapsulating the browser differences in their script libraries, and encapsulating the client script in their server controls. They're also using client-side declarative blocks to define control behavior, which is something I haven't seen before and something that parallels how ASP.NET developers work with controls today on the server side. I think it will also enable some powerful design time enhancements in a future version of Visual Studio (although today they actually break the designer in visual studio, but that's sure to be fixed).
I just completed the ASP.NET “Atlas” hands-on lab. It was very well put-together considering how completely new Atlas is. I imagine a few members of the ASP.NET team probably lost some sleep the week prior to PDC getting all of this put together in time. You can complete the lab yourself -- it's available from the Atlas website. At the moment it requires the Beta 2 version of ASP.NET, but a new lab targeting the RC build of .NET 2.0 should be available very soon.
The lab has 5 parts and shows you first how to set up a master page to hold your Atlas script library references, then quickly moves into useful examples. You learn how to use asynchronous callbacks to web services to set the value of a label (without a postback, naturally) using a bit of javascript. Then again, using a new declarative tag model that is unique to Atlas's approach (as opposed to, say, AJAX.Net) and parallels the ASP.NET server control syntax. The next lab further encapsulates things by using Atlas server controls, which remove the need for the developer to write any client side code. You'll create an auto-completion textbox which is pretty slick, and finally the lab wraps up with a no-code, templated, databound listview which is populated via callbacks.
Considering how new ASP.NET “Atlas” is, it's very impressive. I spoke with one of the Microsofties on the Atlas team, and he explained that one of their goals was to make the whole architecture for this kind of thing easier, as opposed to just creating another library allowing XML-HTTP calls back to the server. To that end, they're encapsulating the browser differences in their script libraries, and encapsulating the client script in their server controls. They're also using client-side declarative blocks to define control behavior, which is something I haven't seen before and something that parallels how ASP.NET developers work with controls today on the server side. I think it will also enable some powerful design time enhancements in a future version of Visual Studio (although today they actually break the designer in visual studio, but that's sure to be fixed).
Just came from Anders Hejlsberg's talk on C# 3.0 and LINQ. You can
actually download
a LINQ tech preview from MSDN, here:
http://msdn.microsoft.com/netframework/future/linq/
The language features that had to go into place to allow for LINQ are quite
impressive, and I'll have to play around with them myself to really wrap my
brain around them since many of them involve rethinking how I think about
programming. However, the potential is very great, since someone
proficient in C# (and LINQ) would be able to effectively work with data from
many different sources (XML, Relational Database, various collection types)
without having to learn separate query languages (SQL, XQuery/XPath, custom
methods) for each one. Having a powerful query language built into the
programming language would also do a lot to help keep business logic in the
application and its components, rather than in the database as stored procedures
or in literal SQL strings within the language.
Jim Allchin gave the second keynote, which included many demos from a variety
of Microsoft teams and a couple of partners. Most of it centered around
new features that will be available in Vista. For example, their virtual
memory system will be able to take advantage of external memory, such as from
USB drives. They showed off a feature called SuperFetch, but unfortunately
I was dozing off for most of that demo so all I saw was that it was searching
the system for various files and (presumably) pre-fetching them.
One security issue Jim stressed was the ability to run applications in a Low
Integrity Mode, which would basically create a sandbox around an application and
allow limits to be placed on its privileges.
New things coming soon include WPF/E which is Windows Presentation
Framework/Everywhere -- a lightweight XAML+JScript implementation for multiple
form factors/devices.
A NetFlix demo showed off many of the 3D graphics capabilities of
Vista. The demo showed off a service to allow a user to add/remove/arrange
movies in their Netflix queue using a Windows client, tablet, or mobile
device.
The bulk of the demos were done by Don Box, Scott Guthrie, Anders Heljsberg
and centered around LINQ (Language INtegrated Query) and Atlas. Basically
this will allow query information to be part of the developer's primary
language, rather than requiring the developer to learn SQL or XPath and a
separate API to use these other languages (e.g. System.Data or
System.Xml). Two of the namespaces demo'd include System.Xml.XLinq and
System.Data.DLinq. Here's an example of the code that one would write
using LINQ to get a list of processes running on one's system and output it to
the console:
var query
=
from p in Process.GetProcesses()
where p.WorkingSet >
1024*1024*4 // 4mb
orderby p.WorkingSet descending
select new
{
p.ProcessName,
p.WorkingSet
};
foreach (var item in
query)
Console.WriteLine(...)
Another interesting feature of this is that
regular expressions can easily be used for the matching in queries.
Further, it is trivial to take the above code and wire it up to data from a
database and/or from an XML document, as they later went on to show.
Scott Guthrie showed off Atlas, which is
currently available for download from the ASP.NET beta
website. It's Microsoft's AJAX story for v2 and looks pretty
slick. You'll find quickstart tutorials and hands-on labs at the link
above.
Bill Gates gave this morning's first keynote at PDC 05. As is
customary, he had a video to augment his presentation. These are usually
very funny, but this one didn't do much for me (it was about Bill as a recruiter
or something, but I didn't think they pulled it off well). However, he did
make a great comment that brought laughter from the crowd. Yesterday,
there was a significant power outage in LA as a result of a technician error
that lasted for like half an hour (I was in the air on my way so I missed
it). So Bill quipped, "You know, I've said many times that the software
industry needs to become as reliable as the electic utitility companies... but I
meant we should become like them, not that they should be like us." :)
Bill covered some new features of Office 12 that make a lot of its existing
features much more discoverable and adds a lot of very cool features that make
customizing and formatting documents/spreadsheets/presentations much
easier. A preview of Vista showed off their gadgets which reminded me
quite a bit of Konfabulator, which I've
been using for a couple of months now. There will also be a lot more RSS
integration in IE7 and Vista.
Bill wrapped up with his vision of the future, which focuses on making SOA a
reliable framework that is simply assumed by application developers as a common
substrate for applications of tomorrow. He also suggested that, while in
the past MS did a great job on the client of integrating applications together
to form the MS Office suite, the next major integration they will do will be on
the server, with Windows Server System and optionally Windows Sharepoint
Services.
Julie and I were having issues with getting Sql Query Notifications to work for ASP.NET cache dependencies (for our DevConnections talks). The trick was this:
sp_dbcmptlevel yourdatabasename,90
Julie did most of the research on this one, with help from Sushil Chordia and Leonid Tsybert from Microsoft. She has more on her blog, but I'm noting here so I might remember this next time.
ScottGu write about the lack of
web project files in VS2005:
VS
2005 Web Project System: What is it and why did we do it?
There have been some threads lately on other blogs about whether this helps
or hurts enterprise developers, with the main counter-point from Scott being
that most of the pain points being reported around ASP.NET 2.0 Beta 2 are in
fact Beta2 issues, not ASP.NET 2.0 issues, and will be corrected at
RTM.
DotNetTreats has a collection
of sample themes for ASP.NET 2.0, along with some tips on how to work with
themes.
I found this post by Rushi Desai on Invalidating cached result sets using SQL Server Query Notification. It's from March so it's a bit out of date, but it has some working ASP.NET sample code (well, working in Beta 2, I presume, but pretty close for RTM).