Category Archives: open source

Spruce and CacheStack

Spruce

I recently created a library that compliments the fantastic Dapper library. I called my library Spruce as a play on the word dapper. The spruce library contains a set of extension methods that simplify querying and saving. When I’m in working in .net land, I primarily use MS Sql server 2008+, so that is what the library is written against. Until I have a need (or get a pull request), I don’t have plans to extend the library to support other databases.

In addition to the querying and saving extensions, Spruce also includes sql schema helpers and a basic migration framework. The migration framework is a simple forward-only (no rollbacks) code based migrations. There are a number of attributes, that can be added to your POCO classes, to define the basic schema for your data. To complement the attributes, Spruce offers a set of extensions specifically for manipulating sql schemas. There are extensions ranging from creating and dropping tables to column schema manipulation. The migration framework ensures that your schema is always where you want it. In cases where there isn’t an extension to accomplish the migration that you need, you can always run the raw sql script via Db.Execute().

Spruce is available as a nuget and is also available on github. There is detailed example usage available at the project’s github page. If you’re interested in seeing Spruce in a real-world project, it is being used with the MvcKickstart project.

 

CacheStack

The other library that I recently created is all about caching. It’s called CacheStack and compliments ServiceStack’s ICacheClient. CacheStack extends typical caching scenarios with the notion of a cache context, allowing you to clear cache items without knowing the specific cache keys. You’re able to setup listeners for the items that you cache and have those cache items invalidate when one of the items you’re listening to fires a trigger. The cache context supports cache profiles that can be defined any way you prefer, be it database, config files, etc. CacheStack also includes a modified version of MvcDonutCaching. My version of donut caching has some bugfixes, performance improvements, and uses ICacheClient for persistence. The really cool part is that you can leverage all of the features of a cache context when using donut caching. This makes it very trivial to clear the output cache of an action, when a model object is updated.

CacheStack is available as a nuget and is also available on github. Like Spruce, there is detailed example usage available on the project’s github page. CacheStack will be incorporated into MvcKickstart in the near future.

Announcing FluentScheduler

Overview

Over the Thanksgiving Holiday, I created an open source project called FluentSchedulerFluentScheduler is a .NET 4 based task scheduler.  It allows you to run tasks/cron jobs from your application.  A fluent api is used to configure schedules for when to run each task.

Why?

In .NET land, I had previously used an xml based task scheduler that only allowed interval based task runtimes.  I wanted more of a .NET 4 way of doing things… With FluentScheduler, not only can you can use a class to represent a task, you can also define your task using a lambda expression.  I really wanted things to be flexible and not try to limit people with how they define their tasks.  Additionally, you can schedule your tasks to run at specific times as well as intervals.

There were many firsts for me with this project:

  • I enjoy using fluent apis, but I have never written one myself.  I figured this project would give me a nice opportunity to dive into creating a fluent interface for a product.  Getting fluent apis right is not easy… I hope you find the api I created to be logical and easy to use.
  • While I have worked on open source projects in the past, it has been a while.  I wanted to explore a different host than Sourceforge, so I chose CodePlex.  There are a lot of other .NET based projects hosted on CodePlex and the site gives project owners options for which source control system you would like to use.  These days, I prefer using Mercurial, which CodePlex offers as an available source control system.  So far, my experience with CodePlex has been excellent.  The tool is easy to use and quick to setup.
  • This is my first official NuGet library.  I have private NuGet packages, but FluentScheduler is part of the official Microsoft feed and available to everyone.

Examples

Detailed usage instructions are available here.  But to give you a taste of how easy this library is to use 🙂

// Schedule a complex task to run immediately and on a monthly interval
Schedule(() =>
	{
		Console.WriteLine("Complex Action Task Starts: " + DateTime.Now);
		Thread.Sleep(1000);
		Console.WriteLine("Complex Action Task Ends: " + DateTime.Now);
	}).ToRunNow().AndEvery(1).Months().OnTheFirst(DayOfWeek.Monday).At(3, 0);

How can I use it?

You can begin using FluentScheduler today by either adding it as a NuGet library package reference or by grabbing the assembly from the project release page.  Once you reference the assembly, please take a look at the documentation for how to configure things.

More Information…

If you’re interested in learning more about the project, check out the project’s homepage.  If you’re interested in contributing, please fork the project and start submitting pull requests 🙂