{"id":331,"date":"2008-06-03T20:56:34","date_gmt":"2008-06-04T01:56:34","guid":{"rendered":"http:\/\/www.wiredprairie.us\/blog\/index.php\/archives\/331"},"modified":"2008-06-03T20:56:34","modified_gmt":"2008-06-04T01:56:34","slug":"velocity-a-rockin-distributed-in-memory-cache-for-aspnet","status":"publish","type":"post","link":"https:\/\/www.wiredprairie.us\/blog\/index.php\/archives\/331","title":{"rendered":"Velocity — a rockin’ distributed in memory cache for ASP.NET"},"content":{"rendered":"

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

What is it? It’s described in the documentation:<\/p>\n

\n

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. <\/p>\n

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. <\/p>\n

When you use “Velocity,” you can retrieve data by using keys or other identifiers, called tags. <\/p>\n<\/blockquote>\n

Download for CTP 1 is here<\/a>.<\/p>\n

Run the installation — and at the end you’ll be asked a few simple starter questions:<\/p>\n

\"image\"<\/a> <\/p>\n

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).<\/p>\n

\"image\"<\/a> <\/p>\n

Installed. Create a new web site in Visual Studio 2008:<\/p>\n

\"image\"<\/a><\/p>\n

Add a reference to pull in the necessary settings into your web site: <\/p>\n

\"image\"<\/a> <\/p>\n

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:<\/p>\n

CacheBaseLibrary.dll<\/b>, ClientLibrary.dll<\/b>, FabricCommon.dll<\/b>, CASBase.dll<\/b>, and CASClient.dll<\/b><\/p>\n

 <\/p>\n

\"image\"<\/a> <\/p>\n

Next, adjust the web.config file per the instructions. <\/p>\n

I tweaked the dcacheClient settings to match those I set when the first installed Velocity.<\/p>\n

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

<\/a><\/a><\/p>\n

I added the required sections to the configSections in web.config, and also the “fabric” section:<\/p>\n

<<\/span>configuration<\/span>>\n    <<\/span>configSections<\/span>>\n<\/span><\/pre>\n

<\/a><\/p>\n

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

<\/a><\/p>\n

    <\/<\/span>configSections<\/span>><\/span><\/pre>\n

<\/a><\/p>\n

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

<\/a><\/p>\n

<\/<\/span>configuration<\/span>><\/span><\/pre>\n

<\/a><\/p>\n

Added some code, then run (the code I used is shown below).<\/p>\n

 <\/p>\n

Unfortunately, this is the first error I encountered:<\/p>\n

Access to the path ‘C:\\Windows\\system32\\CacheClientLog.log’ is denied.<\/i><\/p>\n

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). <\/p>\n

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.”<\/p>\n

Using the Velocity Administration tool, I verified that the host was now running:<\/p>\n

\"image\"<\/a> <\/p>\n

(Silverwindow is the name of my laptop, a MacBook Pro running Windows Vista).<\/p>\n

For reasons I don’t understand, after rebooting, the location of the CacheClientLog.log location changed to here:<\/p>\n

C:\\Program Files\\Microsoft Visual Studio 9.0\\Common7\\IDE. <\/p>\n

So, I repeated the task of creating the empty file and associating the proper permissions as described above (again).<\/p>\n

Here’s what my sample application looked like.<\/p>\n

\"image\"<\/a> <\/p>\n

In the default.aspx page for my web site, I added a few controls:<\/p>\n

<%<\/span>@ <\/span>Page <\/span>Language<\/span>=\"C#\" <\/span>AutoEventWireup<\/span>=\"true\"  <\/span>CodeFile<\/span>=\"Default.aspx.cs\" <\/span>Inherits<\/span>=\"_Default\" <\/span>%>\n\n<\/span><!<\/span>DOCTYPE <\/span>html PUBLIC <\/span>\"-\/\/W3C\/\/DTD XHTML 1.0 Transitional\/\/EN\" 
\"http:\/\/www.w3.org\/TR\/xhtml1\/DTD\/xhtml1-transitional.dtd\">\n\n<<\/span>html <\/span>xmlns<\/span>=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<<\/span>head <\/span>runat<\/span>=\"server\">\n <<\/span>title<\/span>><\/span>Untitled Page<\/<\/span>title<\/span>>\n<\/<\/span>head<\/span>>\n<<\/span>body<\/span>>\n <<\/span>form <\/span>id<\/span>=\"form1\" <\/span>runat<\/span>=\"server\">\n <<\/span>div<\/span>>\n \n <<\/span>asp<\/span>:<\/span>TextBox <\/span>ID<\/span>=\"txtToSet\" <\/span>runat<\/span>=\"server\"><\/<\/span>asp<\/span>:<\/span>TextBox<\/span>>\n <<\/span>asp<\/span>:<\/span>Button <\/span>ID<\/span>=\"btnSetIntoCache\" <\/span>runat<\/span>=\"server\"
<\/span> onclick<\/span>=\"btnSetIntoCache_Click\" \n <\/span>Text<\/span>=\"Set\" \/>\n <<\/span>br <\/span>\/>\n <<\/span>asp<\/span>:<\/span>Label <\/span>ID<\/span>=\"lblValue\" <\/span>runat<\/span>=\"server\"><\/<\/span>asp<\/span>:<\/span>Label<\/span>>\n <<\/span>asp<\/span>:<\/span>Button <\/span>ID<\/span>=\"btnGet\" <\/span>runat<\/span>=\"server\"
<\/span>onclick<\/span>=\"btnGet_Click\" <\/span>Text<\/span>=\"Get\" \/>\n <\/<\/span>div<\/span>>\n <\/<\/span>form<\/span>>\n<\/<\/span>body<\/span>>\n<\/<\/span>html<\/span>><\/span><\/pre>\n

<\/a>And, then in the code-behind:<\/p>\n

using <\/span>System;\nusing <\/span>System.Configuration;\nusing <\/span>System.Data;\nusing <\/span>System.Linq;\nusing <\/span>System.Web;\nusing <\/span>System.Web.Security;\nusing <\/span>System.Web.UI;\nusing <\/span>System.Web.UI.HtmlControls;\nusing <\/span>System.Web.UI.WebControls;\nusing <\/span>System.Web.UI.WebControls.WebParts;\nusing <\/span>System.Xml.Linq;\nusing <\/span>System.Data.Caching;\n\npublic partial class <\/span>_Default <\/span>: System.Web.UI.Page \n<\/span>{\n    protected void <\/span>Page_Load(object <\/span>sender, EventArgs <\/span>e)\n    {\n\n    }\n    protected void <\/span>btnSetIntoCache_Click(object <\/span>sender, EventArgs <\/span>e)\n    {\n        CacheFactory <\/span>CacheCluster1 = new <\/span>CacheFactory<\/span>();\n        Cache <\/span>cache1 = CacheCluster1.GetCache(\"default\"<\/span>);\n\n        cache1.Add(\"cacheThis\"<\/span>, txtToSet.Text);\n\n    }\n    protected void <\/span>btnGet_Click(object <\/span>sender, EventArgs <\/span>e)\n    {\n        CacheFactory <\/span>CacheCluster1 = new <\/span>CacheFactory<\/span>();\n        Cache <\/span>cache1 = CacheCluster1.GetCache(\"default\"<\/span>);\n\n        lblValue.Text = (string<\/span>) cache1.Get(\"cacheThis\"<\/span>);\n    }\n}<\/pre>\n

<\/a> <\/p>\n

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.  <\/p>\n

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

The location of the ClusterConfig.xml file is currently specified in the DistributedCache.exe.config file, which is installed here by default:<\/p>\n

C:\\Program Files\\Microsoft Distributed Cache\\V1.0\\DistributedCache.exe.config<\/p>\n

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.<\/p>\n

The cache can also store any .NET serializable object — not just strings.<\/p>\n

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.\n<\/p>\n

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.\n<\/p>\n

When you use “Velocity,” you can retrieve data by using keys or other identifiers, called tags.\n<\/p>\n

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. <\/p>\n","protected":false},"excerpt":{"rendered":"

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 […]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"spay_email":"","jetpack_publicize_message":"","jetpack_is_tweetstorm":false,"jetpack_publicize_feature_enabled":true},"categories":[4,8],"tags":[],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/pd5QIe-5l","jetpack_likes_enabled":true,"jetpack-related-posts":[{"id":426,"url":"https:\/\/www.wiredprairie.us\/blog\/index.php\/archives\/426","url_meta":{"origin":331,"position":0},"title":"Visual WebGUI — Uh? Neat technology for someone else.","date":"July 16, 2008","format":false,"excerpt":"At the top of the page linked above, you can try the Ajax version or the Silverlight version of their web-mail demo. Try it. I won't say that I'm not impressed by what they've accomplished technically. It's impressive. They use a WinForms designer to build parts of the user interface\u2026","rel":"","context":"In "Coding"","img":{"alt_text":"image","src":"https:\/\/i0.wp.com\/www.wiredprairie.us\/blog\/wp-content\/uploads\/2008\/07\/image-thumb2.png?resize=350%2C200","width":350,"height":200},"classes":[]},{"id":217,"url":"https:\/\/www.wiredprairie.us\/blog\/index.php\/archives\/217","url_meta":{"origin":331,"position":1},"title":"The ASP.NET Single Page Interface and AJAX Patterns","date":"May 9, 2008","format":false,"excerpt":"Posted on MSDN, by Dino Esposito, \"Single Page Interface and AJAX Patterns.\" What is it? From the article... Single-Page Interface Model To take full advantage of AJAX, you need to have all of your features, or at least most of them, in a single page. This is known as the\u2026","rel":"","context":"In "Coding"","img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":788,"url":"https:\/\/www.wiredprairie.us\/blog\/index.php\/archives\/788","url_meta":{"origin":331,"position":2},"title":"Switched my web site to DreamHost","date":"June 7, 2009","format":false,"excerpt":"I switched from my ASP.NET host (at Crystal Tech) to a LAMP host (Dream Host). I really hadn\u2019t been using the ASP.NET features at all and the cost was about $10 more a month than I could spend elsewhere. After some searching, I decided on DreamHost. The prices are competitive,\u2026","rel":"","context":"In "General"","img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":388,"url":"https:\/\/www.wiredprairie.us\/blog\/index.php\/archives\/388","url_meta":{"origin":331,"position":3},"title":"Silverlight Weather Demonstration","date":"June 26, 2008","format":false,"excerpt":"Demonstration available here. (You'll need to wait for a moment while it loads the first time). I've created a reasonably simple, yet multi-technology (and discipline) demonstration using Silverlight for the user interface and ASP.NET as the back-end. The demonstration uses: Silverlight 2.0 Data binding Delayed downloading of images \"Web services\"\u2026","rel":"","context":"In "Coding"","img":{"alt_text":"","src":"https:\/\/i0.wp.com\/www.wiredprairie.us\/blog\/wp-content\/uploads\/2008\/06\/image21.png?resize=350%2C200","width":350,"height":200},"classes":[]},{"id":402,"url":"https:\/\/www.wiredprairie.us\/blog\/index.php\/archives\/402","url_meta":{"origin":331,"position":4},"title":"Linking to functionality within a Silverlight application","date":"July 9, 2008","format":false,"excerpt":"When the ASP.NET 3.5 Extensions are released, it will be easier to manage the history of your Silverlight application, and provide working links to areas of functionality. Raj demonstrates a technique using the beta extensions from Silverlight. The technique uses the new addHistoryPoint method of Sys.Application. Yahoo has some code\u2026","rel":"","context":"In "Coding"","img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":2224,"url":"https:\/\/www.wiredprairie.us\/blog\/index.php\/archives\/2224","url_meta":{"origin":331,"position":5},"title":"Flutter Demo application linking to BoardGameGeek.Com’s Hot Game List","date":"February 26, 2018","format":false,"excerpt":"I've built a slightly more interesting application using Flutter.\u00a0 Using an XML feed from BoardGameGeek's API, the application displays a list of the current hot games complete with thumbnail images. Here's the code. I used a standard Flutter app template and also added a few packages to the project. I've\u2026","rel":"","context":"In "Coding"","img":{"alt_text":"Hulk Smash Layout","src":"https:\/\/i0.wp.com\/www.wiredprairie.us\/blog\/wp-content\/uploads\/2018\/02\/2018-02-26-19_45_39-Hulk-Smash-Meme-Generator-Imgflip.png?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]}],"_links":{"self":[{"href":"https:\/\/www.wiredprairie.us\/blog\/index.php\/wpjson\/wp\/v2\/posts\/331"}],"collection":[{"href":"https:\/\/www.wiredprairie.us\/blog\/index.php\/wpjson\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wiredprairie.us\/blog\/index.php\/wpjson\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wiredprairie.us\/blog\/index.php\/wpjson\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wiredprairie.us\/blog\/index.php\/wpjson\/wp\/v2\/comments?post=331"}],"version-history":[{"count":0,"href":"https:\/\/www.wiredprairie.us\/blog\/index.php\/wpjson\/wp\/v2\/posts\/331\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.wiredprairie.us\/blog\/index.php\/wpjson\/wp\/v2\/media?parent=331"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wiredprairie.us\/blog\/index.php\/wpjson\/wp\/v2\/categories?post=331"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wiredprairie.us\/blog\/index.php\/wpjson\/wp\/v2\/tags?post=331"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}