Velocity — a rockin’ distributed in memory cache for ASP.NET

Velocity, the code-name for a new in-memory distributed caching system for ASP.NET was released as a Community Tech Preview today.

What is it? It’s described in the documentation:

Microsoft project code named “Velocity” provides a highly scalable in-memory application cache for all kinds of data. By using cache, your application performance can improve significantly by avoiding unnecessary calls to the data source.

By using distributed cache, your application can scale to match an increasing demand with increasing throughput. “Velocity” distributed cache is provided in the form of a cache cluster, simplifying your application code by managing the complexities of load balancing behind the scenes.

When you use “Velocity,” you can retrieve data by using keys or other identifiers, called tags.

Download for CTP 1 is here.

Run the installation — and at the end you’ll be asked a few simple starter questions:

image

The settings above can be adjusted later if you don’t like them. Unblock the EXE in your firewall settings if needed (I didn’t need to when using localhost as my destination server as shown below).

image

Installed. Create a new web site in Visual Studio 2008:

image

Add a reference to pull in the necessary settings into your web site:

image

You’ll need to reference a few assemblies. The simplest way to get them all is to reference them directly (rather than copying them as the instructions say). VS 2008 won’t complain.The following files are needed:

CacheBaseLibrary.dll, ClientLibrary.dll, FabricCommon.dll, CASBase.dll, and CASClient.dll

 

image

Next, adjust the web.config file per the instructions.

I tweaked the dcacheClient settings to match those I set when the first installed Velocity.

<dcacheClient deployment="simple" localCache="false">
    <hosts>
        <!--List of hosts -->
        <host name="localhost" cachePort="22233" cacheHostName="MyCluster"/>
    </hosts>
</dcacheClient>

I added the required sections to the configSections in web.config, and also the “fabric” section:

<configuration>
    <configSections>

        <section name="dcacheClient" type="System.Configuration.IgnoreSectionHandler" allowLocation="true" allowDefinition="Everywhere"/>
        <section name="fabric" type="System.Fabric.Common.ConfigFile, FabricCommon" allowLocation="true" allowDefinition="Everywhere"/>

    </configSections>

    <fabric>
        <section name="logging" path="">
            <collection name="sinks" collectionType="list">
                <customType className="System.Fabric.Common.EventLogger,FabricCommon" sinkName="System.Fabric.Common.ConsoleSink,FabricCommon" sinkParam="" defaultLevel="-1"/>
                <customType className="System.Fabric.Common.EventLogger,FabricCommon" sinkName="System.Fabric.Common.FileEventSink,FabricCommon" sinkParam="CacheClientLog" defaultLevel="1"/>
                <customType className="System.Fabric.Common.EventLogger,FabricCommon" sinkName="System.Data.Caching.ETWSink, CacheBaseLibrary" sinkParam="" defaultLevel="-1"/>
            </collection>
        </section>
    </fabric>

</configuration>

Added some code, then run (the code I used is shown below).

 

Unfortunately, this is the first error I encountered:

Access to the path ‘C:\Windows\system32\CacheClientLog.log’ is denied.

Since I’m using the ASP.NET Development Server, I started an administrative instance of notepad and created a blank CacheClientLog.log file in the directory. I then set full permissions on the file for my user account (aaron in my case).

Next, I discovered that the service EXE hadn’t been properly installed. After some false-starts, I rebooted, and again, as an admin user, used the installutil.exe utility from the .NET SDK to install the service (as I had uinstalled it). Using the Services management console, I started the service, “DistributedCacheService.”

Using the Velocity Administration tool, I verified that the host was now running:

image

(Silverwindow is the name of my laptop, a MacBook Pro running Windows Vista).

For reasons I don’t understand, after rebooting, the location of the CacheClientLog.log location changed to here:

C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE.

So, I repeated the task of creating the empty file and associating the proper permissions as described above (again).

Here’s what my sample application looked like.

image

In the default.aspx page for my web site, I added a few controls:

<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <
html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title>Untitled Page</title> </head> <body> <form id="form1" runat="server"> <div> <asp:TextBox ID="txtToSet" runat="server"></asp:TextBox> <asp:Button ID="btnSetIntoCache" runat="server"
onclick="btnSetIntoCache_Click" Text="Set" /> <br /> <asp:Label ID="lblValue" runat="server"></asp:Label> <asp:Button ID="btnGet" runat="server"
onclick="btnGet_Click" Text="Get" /> </div> </form> </body> </html>

And, then in the code-behind:

using System;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.Caching;

public partial class _Default : System.Web.UI.Page 
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void btnSetIntoCache_Click(object sender, EventArgs e)
    {
        CacheFactory CacheCluster1 = new CacheFactory();
        Cache cache1 = CacheCluster1.GetCache("default");

        cache1.Add("cacheThis", txtToSet.Text);

    }
    protected void btnGet_Click(object sender, EventArgs e)
    {
        CacheFactory CacheCluster1 = new CacheFactory();
        Cache cache1 = CacheCluster1.GetCache("default");

        lblValue.Text = (string) cache1.Get("cacheThis");
    }
}

 

The default cache I referred to in the test code is called default — as that’s the name that is specified in the ClusterConfig.xml file that was created during the installation. 

    <caches>
      <cache name="default" type="partitioned">
        <policy>
          <eviction type="lru" />
          <expiration isExpirable="true" defaultTTL="10" />
        </policy>
      </cache>
    </caches>    

The location of the ClusterConfig.xml file is currently specified in the DistributedCache.exe.config file, which is installed here by default:

C:\Program Files\Microsoft Distributed Cache\V1.0\DistributedCache.exe.config

Run the web application. Set some value into the cache (using the “Set” button). Get it back out (“Get” button). Shut down the ASP.NET development server. Run the application again — you’ll see how the cached value is still there (assuming you haven’t waited too long). Cool.

The cache can also store any .NET serializable object — not just strings.

Microsoft project code named “Velocity” provides a highly scalable in-memory application cache for all kinds of data. By using cache, your application performance can improve significantly by avoiding unnecessary calls to the data source.

By using distributed cache, your application can scale to match an increasing demand with increasing throughput. “Velocity” distributed cache is provided in the form of a cache cluster, simplifying your application code by managing the complexities of load balancing behind the scenes.

When you use “Velocity,” you can retrieve data by using keys or other identifiers, called tags.

Check it out for yourself. This is a great addition to ASP.NET and truly puts ASP.NET into the competitive ‘big-scale’ enterprise application market without the need for expensive third party products.

Adobe PDF files, not printable anymore?

Just announced ….

Acrobat 9 includes support for embedded Flash (SWF) content. The Flash content, as suggested by the AEC Product Manager here, could be video, audio, presentations, etc. It’s interesting to me that a file format that (maybe incorrectly on my part) always suggested, “WYSIWYG” no matter where you view it (screen to printer) may no longer offer this assurance; this is a reasonably large change.

From a non-purist standpoint, it’s a brilliant move to further the inroads Adobe is making on the desktop. From eliminating or reducing HTML in many web applications (Flash and Flex), to creating installable applications (Adobe AIR), now to truly rich interactive documents available on a wide variety of platforms.

I wonder if the other PDF Reader vendors (such as FoxIt Reader) will be able to compete? Although the PDF specification is open … it may be difficult to embed the Flash viewer (the license may explicitly forbid it), but from a technical perspective, it may be challenging.

What do you think about this? I can’t even recall if the XPS format and associated viewer in WPF could do something like this (anyone know?). What do you expect Microsoft’s reaction to this will be?

Extensibility via Flash / Flex in Adobe platform …

Interesting.

“Therefore, we’re looking at letting upcoming versions of Photoshop and–as far as I know–all Creative Suite applications be extended via SWF panels (palettes) created in Adobe Flash or Flex.”

There seems to be a lot of negative comments about usability, platform inconsistency, etc. However, I’d argue those are short-sited. At first, it may be true that plug-ins developed via this technique aren’t consistent, but I’d rather suffer through a little bit of pain for long term gain. The Flash platform is becoming more and more capable, and by providing extensibility through a simpler, widely adopted language, it should help vastly increase the number of available plug-ins.

Platforms are often rough in V1 — but give them a chance to grow and see what develops.