diff --git a/examples/Spring/Spring.CachingQuickStart/Spring.CachingQuickStart.2008.sln b/examples/Spring/Spring.CachingQuickStart/Spring.CachingQuickStart.2008.sln new file mode 100644 index 00000000..5861b8d8 --- /dev/null +++ b/examples/Spring/Spring.CachingQuickStart/Spring.CachingQuickStart.2008.sln @@ -0,0 +1,20 @@ + +Microsoft Visual Studio Solution File, Format Version 10.00 +# Visual Studio 2008 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Spring.CachingQuickStart.Web", "src\Spring.CachingQuickStart.Web\Spring.CachingQuickStart.Web.2008.csproj", "{F02A190A-C98A-434B-8203-D9E5EBCDE9DB}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {F02A190A-C98A-434B-8203-D9E5EBCDE9DB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {F02A190A-C98A-434B-8203-D9E5EBCDE9DB}.Debug|Any CPU.Build.0 = Debug|Any CPU + {F02A190A-C98A-434B-8203-D9E5EBCDE9DB}.Release|Any CPU.ActiveCfg = Release|Any CPU + {F02A190A-C98A-434B-8203-D9E5EBCDE9DB}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/examples/Spring/Spring.CachingQuickStart/Spring.CachingQuickStart.2010.sln b/examples/Spring/Spring.CachingQuickStart/Spring.CachingQuickStart.2010.sln new file mode 100644 index 00000000..3a114946 --- /dev/null +++ b/examples/Spring/Spring.CachingQuickStart/Spring.CachingQuickStart.2010.sln @@ -0,0 +1,20 @@ + +Microsoft Visual Studio Solution File, Format Version 11.00 +# Visual Studio 2010 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Spring.CachingQuickStart.Web.2010", "src\Spring.CachingQuickStart.Web\Spring.CachingQuickStart.Web.2010.csproj", "{F02A190A-C98A-434B-8203-D9E5EBCDE9DB}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {F02A190A-C98A-434B-8203-D9E5EBCDE9DB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {F02A190A-C98A-434B-8203-D9E5EBCDE9DB}.Debug|Any CPU.Build.0 = Debug|Any CPU + {F02A190A-C98A-434B-8203-D9E5EBCDE9DB}.Release|Any CPU.ActiveCfg = Release|Any CPU + {F02A190A-C98A-434B-8203-D9E5EBCDE9DB}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/examples/Spring/Spring.CachingQuickStart/src/Spring.CachingQuickStart.Web/Default.aspx b/examples/Spring/Spring.CachingQuickStart/src/Spring.CachingQuickStart.Web/Default.aspx new file mode 100644 index 00000000..bf9e6fb2 --- /dev/null +++ b/examples/Spring/Spring.CachingQuickStart/src/Spring.CachingQuickStart.Web/Default.aspx @@ -0,0 +1,111 @@ +<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="Spring.CachingQuickStart.Web._Default" %> + + + + + + Caching QuickStart + + +
+
+

+ Using Cache Aspect: +

+

+ +
+ +
+ +

+
+

+ +
+ + + + + + + + + + + + + + + +
+ ID + + TITLE +
+ <%# Eval("ID") %> + + <%# Eval("Title") %> +
+ +
+

+
+

+ ID:  +
+ Title:  +
+ +

+
+

+ +
+ +

+
+

+  

+

+ Using Caching API (ICache interface) programmatically to show cache content: +

+

+ + + + + + + + + + + + + + + +
+ KEY + + VALUE +
+ <%# Eval("Key") %> + + <%# Eval("Value") %> +
+ +
+
+ + +

+
+
+ + diff --git a/examples/Spring/Spring.CachingQuickStart/src/Spring.CachingQuickStart.Web/Default.aspx.cs b/examples/Spring/Spring.CachingQuickStart/src/Spring.CachingQuickStart.Web/Default.aspx.cs new file mode 100644 index 00000000..f7a9fbaf --- /dev/null +++ b/examples/Spring/Spring.CachingQuickStart/src/Spring.CachingQuickStart.Web/Default.aspx.cs @@ -0,0 +1,119 @@ +using System; +using System.Collections.Generic; + +using Spring.Context; +using Spring.Context.Support; +using Spring.Caching; + +using Spring.CachingQuickStart.Services; + +namespace Spring.CachingQuickStart.Web +{ + public partial class _Default : System.Web.UI.Page + { + protected void Page_Load(object sender, EventArgs e) + { + } + + // GetById + protected void GetByIdButton_Click(object sender, EventArgs e) + { + IApplicationContext ctx = ContextRegistry.GetContext(); + IMovieService movieService = ctx.GetObject("MovieService") as IMovieService; + + Movie movie = movieService.GetById(Int32.Parse(this.GetByIdTextBox.Text)); + + this.GetByIdLabel.Text = movie.Title; + + UpdateCacheContent(); + } + + // FindAll + protected void FindAllButton_Click(object sender, EventArgs e) + { + IApplicationContext ctx = ContextRegistry.GetContext(); + IMovieService movieService = ctx.GetObject("MovieService") as IMovieService; + + IEnumerable movies = movieService.FindAll(); + + this.FindAllRepeater.DataSource = movies; + this.FindAllRepeater.DataBind(); + + UpdateCacheContent(); + } + + // Save + protected void SaveButton_Click(object sender, EventArgs e) + { + IApplicationContext ctx = ContextRegistry.GetContext(); + IMovieService movieService = ctx.GetObject("MovieService") as IMovieService; + + Movie movie = new Movie( + Int32.Parse(this.SaveIdTextBox.Text), + this.SaveTitleTextBox.Text); + + movieService.Save(movie); + + UpdateCacheContent(); + } + + // Delete + protected void DeleteButton_Click(object sender, EventArgs e) + { + IApplicationContext ctx = ContextRegistry.GetContext(); + IMovieService movieService = ctx.GetObject("MovieService") as IMovieService; + + Movie movie = new Movie( + Int32.Parse(this.DeleteIdTextBox.Text), + "NotUsed"); + + movieService.Delete(movie); + + UpdateCacheContent(); + } + + + // Using Caching API programmatically + + protected void ClearButton_Click(object sender, EventArgs e) + { + ClearCacheContent(); + UpdateCacheContent(); + } + + protected void RefreshButton_Click(object sender, EventArgs e) + { + UpdateCacheContent(); + } + + private void ClearCacheContent() + { + IApplicationContext ctx = ContextRegistry.GetContext(); + ICache cache = ctx.GetObject("DefaultCache") as ICache; + + cache.Clear(); + } + + private void UpdateCacheContent() + { + IList cacheEntries = new List(); + + IApplicationContext ctx = ContextRegistry.GetContext(); + ICache cache = ctx.GetObject("DefaultCache") as ICache; + + foreach (object key in cache.Keys) + { + cacheEntries.Add(new CacheEntry() { Key = key, Value = cache.Get(key) }); + } + + this.CacheRepeater.DataSource = cacheEntries; + this.CacheRepeater.DataBind(); + } + + public class CacheEntry + { + public object Key { get; set; } + public object Value { get; set; } + } + } +} diff --git a/examples/Spring/Spring.CachingQuickStart/src/Spring.CachingQuickStart.Web/Default.aspx.designer.cs b/examples/Spring/Spring.CachingQuickStart/src/Spring.CachingQuickStart.Web/Default.aspx.designer.cs new file mode 100644 index 00000000..b991bfd2 --- /dev/null +++ b/examples/Spring/Spring.CachingQuickStart/src/Spring.CachingQuickStart.Web/Default.aspx.designer.cs @@ -0,0 +1,141 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace Spring.CachingQuickStart.Web { + + + public partial class _Default { + + /// + /// form1 control. + /// + /// + /// Auto-generated field. + /// To modify move field declaration from designer file to code-behind file. + /// + protected global::System.Web.UI.HtmlControls.HtmlForm form1; + + /// + /// GetByIdTextBox control. + /// + /// + /// Auto-generated field. + /// To modify move field declaration from designer file to code-behind file. + /// + protected global::System.Web.UI.WebControls.TextBox GetByIdTextBox; + + /// + /// GetByIdButton control. + /// + /// + /// Auto-generated field. + /// To modify move field declaration from designer file to code-behind file. + /// + protected global::System.Web.UI.WebControls.Button GetByIdButton; + + /// + /// GetByIdLabel control. + /// + /// + /// Auto-generated field. + /// To modify move field declaration from designer file to code-behind file. + /// + protected global::System.Web.UI.WebControls.Label GetByIdLabel; + + /// + /// FindAllButton control. + /// + /// + /// Auto-generated field. + /// To modify move field declaration from designer file to code-behind file. + /// + protected global::System.Web.UI.WebControls.Button FindAllButton; + + /// + /// FindAllRepeater control. + /// + /// + /// Auto-generated field. + /// To modify move field declaration from designer file to code-behind file. + /// + protected global::System.Web.UI.WebControls.Repeater FindAllRepeater; + + /// + /// SaveIdTextBox control. + /// + /// + /// Auto-generated field. + /// To modify move field declaration from designer file to code-behind file. + /// + protected global::System.Web.UI.WebControls.TextBox SaveIdTextBox; + + /// + /// SaveTitleTextBox control. + /// + /// + /// Auto-generated field. + /// To modify move field declaration from designer file to code-behind file. + /// + protected global::System.Web.UI.WebControls.TextBox SaveTitleTextBox; + + /// + /// SaveButton control. + /// + /// + /// Auto-generated field. + /// To modify move field declaration from designer file to code-behind file. + /// + protected global::System.Web.UI.WebControls.Button SaveButton; + + /// + /// DeleteIdTextBox control. + /// + /// + /// Auto-generated field. + /// To modify move field declaration from designer file to code-behind file. + /// + protected global::System.Web.UI.WebControls.TextBox DeleteIdTextBox; + + /// + /// DeleteButton control. + /// + /// + /// Auto-generated field. + /// To modify move field declaration from designer file to code-behind file. + /// + protected global::System.Web.UI.WebControls.Button DeleteButton; + + /// + /// CacheRepeater control. + /// + /// + /// Auto-generated field. + /// To modify move field declaration from designer file to code-behind file. + /// + protected global::System.Web.UI.WebControls.Repeater CacheRepeater; + + /// + /// ClearButton control. + /// + /// + /// Auto-generated field. + /// To modify move field declaration from designer file to code-behind file. + /// + protected global::System.Web.UI.WebControls.Button ClearButton; + + /// + /// RefreshButton control. + /// + /// + /// Auto-generated field. + /// To modify move field declaration from designer file to code-behind file. + /// + protected global::System.Web.UI.WebControls.Button RefreshButton; + } +} diff --git a/examples/Spring/Spring.CachingQuickStart/src/Spring.CachingQuickStart.Web/Services/IMovieService.cs b/examples/Spring/Spring.CachingQuickStart/src/Spring.CachingQuickStart.Web/Services/IMovieService.cs new file mode 100644 index 00000000..584ee2f1 --- /dev/null +++ b/examples/Spring/Spring.CachingQuickStart/src/Spring.CachingQuickStart.Web/Services/IMovieService.cs @@ -0,0 +1,39 @@ +#region License + +/* + * Copyright 2002-2011 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#endregion + +using System.Collections.Generic; + +namespace Spring.CachingQuickStart.Services +{ + /// + /// Describes the interface for manipulating movies independent of how + /// said movies are actually stored (text file, database, etc). + /// + public interface IMovieService + { + Movie GetById(int id); + + IEnumerable FindAll(); + + void Save(Movie movie); + + void Delete(Movie movie); + } +} diff --git a/examples/Spring/Spring.CachingQuickStart/src/Spring.CachingQuickStart.Web/Services/Movie.cs b/examples/Spring/Spring.CachingQuickStart/src/Spring.CachingQuickStart.Web/Services/Movie.cs new file mode 100644 index 00000000..35c3a296 --- /dev/null +++ b/examples/Spring/Spring.CachingQuickStart/src/Spring.CachingQuickStart.Web/Services/Movie.cs @@ -0,0 +1,52 @@ +#region License + +/* + * Copyright 2002-2011 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#endregion + +using System; + +namespace Spring.CachingQuickStart.Services +{ + /// + /// An object that describes a movie. + /// + public class Movie + { + public int ID { get; set; } + public string Title { get; set; } + + /// + /// Creates a new instance of the + /// class. + /// + /// The ID of the movie. + /// The title of the movie. + public Movie(int id, string title) + { + this.ID = id; + this.Title = title; + } + + public override string ToString() + { + return String.Format( + "Movie[ID='{0}'; Title='{1}']", + this.ID, this.Title); + } + } +} diff --git a/examples/Spring/Spring.CachingQuickStart/src/Spring.CachingQuickStart.Web/Services/MovieService.cs b/examples/Spring/Spring.CachingQuickStart/src/Spring.CachingQuickStart.Web/Services/MovieService.cs new file mode 100644 index 00000000..7d46d6f9 --- /dev/null +++ b/examples/Spring/Spring.CachingQuickStart/src/Spring.CachingQuickStart.Web/Services/MovieService.cs @@ -0,0 +1,83 @@ +#region License + +/* + * Copyright 2002-2011 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#endregion + +using System; +using System.Collections.Generic; + +using Spring.Caching; + +namespace Spring.CachingQuickStart.Services +{ + /// + /// Basic implementation of the IMovieService interface. + /// + public class MovieService : IMovieService + { + private IDictionary movies; + + public MovieService() + { + this.movies = new Dictionary(); + this.movies.Add(1, new Movie(1, "La vita e bella")); + this.movies.Add(2, new Movie(2, "Blue Velvet")); + } + + [CacheResult("DefaultCache", "'Movie-' + #id")] + public Movie GetById(int id) + { + if (this.movies.ContainsKey(id)) + { + return this.movies[id]; + } + throw new ApplicationException(String.Format("Movie (ID='{0}') does not exist.", id)); + } + + [CacheResult("DefaultCache", "'AllMovies'", TimeToLive = "2m")] + [CacheResultItems("DefaultCache", "'Movie-' + ID")] + public IEnumerable FindAll() + { + return movies.Values; + } + + [InvalidateCache("DefaultCache", Keys = "'AllMovies'")] + public void Save( + [CacheParameter("DefaultCache", "'Movie-' + ID")]Movie movie) + { + if (this.movies.ContainsKey(movie.ID)) + { + this.movies[movie.ID] = movie; + } + else + { + this.movies.Add(movie.ID, movie); + } + } + + [InvalidateCache("DefaultCache", Keys = "'Movie-' + #movie.ID")] + [InvalidateCache("DefaultCache", Keys = "'AllMovies'")] + public void Delete(Movie movie) + { + if (this.movies.ContainsKey(movie.ID)) + { + this.movies.Remove(movie.ID); + } + } + } +} diff --git a/examples/Spring/Spring.CachingQuickStart/src/Spring.CachingQuickStart.Web/Spring.CachingQuickStart.Web.2008.csproj b/examples/Spring/Spring.CachingQuickStart/src/Spring.CachingQuickStart.Web/Spring.CachingQuickStart.Web.2008.csproj new file mode 100644 index 00000000..d50c97d8 --- /dev/null +++ b/examples/Spring/Spring.CachingQuickStart/src/Spring.CachingQuickStart.Web/Spring.CachingQuickStart.Web.2008.csproj @@ -0,0 +1,96 @@ + + + Debug + AnyCPU + 9.0.30729 + 2.0 + {F02A190A-C98A-434B-8203-D9E5EBCDE9DB} + {349c5851-65df-11da-9384-00065b846f21};{fae04ec0-301f-11d3-bf4b-00c04f79efbc} + Library + Properties + Spring.CachingQuickStart + Spring.CachingQuickStart.Web + v2.0 + + + true + full + false + bin\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + bin\ + TRACE + prompt + 4 + + + + False + ..\..\..\..\..\bin\net\2.0\debug\Spring.Aop.dll + + + False + ..\..\..\..\..\bin\net\2.0\debug\Spring.Core.dll + + + False + ..\..\..\..\..\bin\net\2.0\debug\Spring.Web.dll + + + + + + + + + + + + ASPXCodeBehind + Default.aspx + + + Default.aspx + + + + + + + + + + + + + + + + False + True + 54312 + / + + + False + False + + + False + + + + + \ No newline at end of file diff --git a/examples/Spring/Spring.CachingQuickStart/src/Spring.CachingQuickStart.Web/Spring.CachingQuickStart.Web.2010.csproj b/examples/Spring/Spring.CachingQuickStart/src/Spring.CachingQuickStart.Web/Spring.CachingQuickStart.Web.2010.csproj new file mode 100644 index 00000000..3bad03d7 --- /dev/null +++ b/examples/Spring/Spring.CachingQuickStart/src/Spring.CachingQuickStart.Web/Spring.CachingQuickStart.Web.2010.csproj @@ -0,0 +1,102 @@ + + + + Debug + AnyCPU + 9.0.30729 + 2.0 + {F02A190A-C98A-434B-8203-D9E5EBCDE9DB} + {349c5851-65df-11da-9384-00065b846f21};{fae04ec0-301f-11d3-bf4b-00c04f79efbc} + Library + Properties + Spring.CachingQuickStart + Spring.CachingQuickStart.Web + v4.0 + + + 3.5 + + + false + + + true + full + false + bin\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + bin\ + TRACE + prompt + 4 + + + + False + ..\..\..\..\..\bin\net\4.0\debug\Spring.Aop.dll + + + False + ..\..\..\..\..\bin\net\4.0\debug\Spring.Core.dll + + + False + ..\..\..\..\..\bin\net\4.0\debug\Spring.Web.dll + + + + + + + + + + + ASPXCodeBehind + Default.aspx + + + Default.aspx + + + + + + + + + + + + + + + + False + True + 31290 + / + + + False + False + + + False + + + + + \ No newline at end of file diff --git a/examples/Spring/Spring.CachingQuickStart/src/Spring.CachingQuickStart.Web/Spring.config b/examples/Spring/Spring.CachingQuickStart/src/Spring.CachingQuickStart.Web/Spring.config new file mode 100644 index 00000000..383c3f6e --- /dev/null +++ b/examples/Spring/Spring.CachingQuickStart/src/Spring.CachingQuickStart.Web/Spring.config @@ -0,0 +1,34 @@ + + + + + + + + + + + + + + + + + + + + + + + Spring.CachingQuickStart.Services.* + + + + + CacheAspect + + + + + + diff --git a/examples/Spring/Spring.CachingQuickStart/src/Spring.CachingQuickStart.Web/Web.config b/examples/Spring/Spring.CachingQuickStart/src/Spring.CachingQuickStart.Web/Web.config new file mode 100644 index 00000000..49677d96 --- /dev/null +++ b/examples/Spring/Spring.CachingQuickStart/src/Spring.CachingQuickStart.Web/Web.config @@ -0,0 +1,46 @@ + + + + +
+
+ + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/readme.txt b/readme.txt index 083c8776..75326c59 100644 --- a/readme.txt +++ b/readme.txt @@ -168,6 +168,7 @@ Documented sample applications can be found in "examples": * IoCQuickStart.AppContext - Show use of various IApplicationContext features. * IoCQuickStart.EventRegistry - Show use of loosely coupled eventing features. * AopQuickStart - Show use of AOP features. +* CachingQuickStart - Show use of Caching abstraction. * SpringAir - Show use of Spring.Web features. * Calculator - Show use of Spring.Services features. * WebQuickStart - Show step by step usage of Spring.Web features. @@ -177,7 +178,7 @@ Documented sample applications can be found in "examples": * Data.NHibernate.Northwind - Show use of Spring's NHibernate features. * WCFQuickStart - Show use of DI and AOP with WCF * NMSQuickStart - Sample application using NMS -* MSMQ QuickStart - Sample applicaiton usingMSMQ +* MSMQ QuickStart - Sample application using MSMQ * Quartz Example - Scheduling using Quartz 7. How to build