Permalink
Browse files

Enable caching of views (#458)

Add a checkbox to allow views to be cached as well as table objects.
  • Loading branch information...
jeremeguenther authored and niemyjski committed Mar 14, 2018
1 parent 54c5f96 commit 27fdc72a8683d53c46abfdaa27bb739e542e496a
@@ -19,7 +19,7 @@
<%@ Import Namespace="SchemaExplorer" %>
<%@ Property Name="SourceTable" Type="SchemaExplorer.TableSchema" Category="Connection" Description="Table Object should be based on." %>
<%@ Property Name="SourceTables" Type="SchemaExplorer.TableSchemaCollection" Category="Connection" Description="Tables of the sytem." %>
<%@ Property Name="SourceTables" Type="SchemaExplorer.TableSchemaCollection" Category="Connection" Description="Tables of the system." %>
<%@ Property Name="CreateEntityCache" Optional="True" Type="System.Boolean" Default="False" Category="Options" Description="Should Caching be enabled for this entity." %>
<%@ Property Name="IncludeRelations" Type="System.Boolean" Default="True" Category="Options" Description="Include Collections for Related Entities."%>
@@ -27,6 +27,10 @@
<%@ Property Name="ComponentPattern" Optional="False" Type="MoM.Templates.ComponentPatternType" Category="Pattern" Description="Component Pattern Type." %>
<%@ Property Name="CustomNonMatchingReturnType" Type="CustomNonMatchingReturnType" Default="DataSet" Category="Options" Description="When using custom stored procedures, if the returned rows do not match the fields in an entity, a DataSet or IDataReader will be returned. Choose One. This is useful if you've returned more than one resultset in a custom procedure; you can use a ConvertToDataSet(IDataReader) method in the Utility class to convert that to a DataSet." %>
<%@ Property Name="CreateViewCache" Optional="True" Type="System.Boolean" Default="False" Category="Options" Description="Should Caching be enabled for this view." %>
<%@ Property Name="DotNetVersion" Type="MoM.Templates.DotNetFrameworkVersion" Default="v4_5" Category="02. Framework Generation - Optional" Description="Indicates the Version of Dot Net to target. Options include v2, v3 and v3.5" %>
<%
#region Template Logic
@@ -196,6 +200,52 @@
#endregion <%= MethodNames.Get %> Methods
#region <%=partialClassInternalPrefix%><%= MethodNames.GetAll %>
<% if(CreateViewCache) {%>
/// <summary>
/// Enable Caching on get all
/// Get a complete collection of <see cref="<%= className %>" /> entities.
/// </summary>
/// <param name="_cacheOptions">General features directing what the caching method is doing</param>
/// <param name="_cachePolicy">The Entity Caching policy</param>
/// <returns>a <see cref="<%= collectionClassNameComment %>"/> </returns>
<%= constructorAccessModifier %> <%=collectionClassName %> <%=partialClassInternalPrefix%><%= MethodNames.GetAll %>(<%= GetCacheFunctionParameters(DotNetVersion) %>)
{
#region Initialisation
<%=collectionClassName %> list = null;
#endregion Initialisation
#region Cache
string cacheKey = "<%=className%>.<%=partialClassInternalPrefix%><%= MethodNames.GetAll %>";
if (_cacheOptions == EntityCacheOptions.UpdateCache || _cacheOptions == EntityCacheOptions.RemoveFromCache)
{
EntityCache.RemoveItem(cacheKey);
if (_cacheOptions == EntityCacheOptions.RemoveFromCache)
return null;
}
else
{
list = EntityCache.GetItem<<%=collectionClassName %>>(cacheKey.ToString());
if (list != null)
{
return list;
}
}
#endregion
list = <%= MethodNames.GetAll %>();
if (list != null && list.Count > 0)
EntityCache.AddCache(cacheKey, list, _cachePolicy);
return list;
}
<% } %>
/// <summary>
/// Get a complete collection of <see cref="<%= className %>" /> entities.
/// </summary>
@@ -17,6 +17,7 @@
<%@ Property Name="BLLNameSpace" Optional="True" Type="System.String" Category="Style" Description="Component Namespace." %>
<%@ Property Name="DALNameSpace" Optional="True" Type="System.String" Category="Style" Description="DAL Namespace." %>
<%@ Property Name="UsePartialClass" Type="System.Boolean" Default="true" Category="General" Description="Indicates if partial class should be generated." %>
<%@ Property Name="CreateViewCache" Optional="True" Type="System.Boolean" Default="False" Category="Options" Description="Should Caching be enabled for this view." %>
<%@ Property Name="SourceView" Type="SchemaExplorer.ViewSchema" Category="Connection" Description="View Object should be based on." %>
@@ -36,6 +36,7 @@
<%@ Property Name="TimeStandard" Type="TimeStandardEnum" Default="Local" Category="02. Framework Generation - Optional" Description="Standard used for generating DateTime values. If 'UTC' DateTime is generated based on UtcNow. If 'Local' DateTime is generated based on DateTime.Now" %>
<%@ Property Name="IsConnectionStringAzure" Type="System.Boolean" Default="False" Category="02. Framework Generation - Optional" Description="Indicates if at runtime the netTiersConnectionString is read from Window Azure's ServiceConfiguration.cscfg or from Web.config/app.config." %>
<%@ Property Name="EntityCacheLayer" Type="MoM.Templates.CacheLayer" Default="None" Category="02. Framework Generation - Optional" Description="Indicates if the Cache code should be written for the enabled CacheTables entities using Enterprise Library or System.Runtime.Caching." %>
<%@ Property Name="EnableViewCache" Type="System.Boolean" Default="True" Category="02. Framework Generation - Optional" Description="If a cache layer has been chosen, then also create cache methods for all views" %>
<%-- 3. Namespaces Category --%>
<%@ Property Name="BusinessLogicLayerNameSpace" Type="System.String" Category="03. Namespaces - Required" Description="The sub namespace that is added to the root namespace for the entities." Default="Entities" Optional="False" %>
@@ -3724,6 +3725,7 @@
this.GetTemplate("ComponentViewServiceBase.cst").SetProperty("BLLNameSpace", BLLNameSpace);
this.GetTemplate("ComponentViewServiceBase.cst").SetProperty("DALNameSpace", DALNameSpace);
this.GetTemplate("ComponentViewServiceBase.cst").SetProperty("UsePartialClass", UsePartialClass);
this.GetTemplate("ComponentViewServiceBase.cst").SetProperty("CreateViewCache", (EnableViewCache && EntityCacheLayer != MoM.Templates.CacheLayer.None));
this.GetTemplate("ComponentViewServiceBase.cst").SetProperty("SourceView", SourceView);
//this.GetTemplate("ComponentViewServiceBase.cst").SetProperty("SourceViews", templateSourceViews);

0 comments on commit 27fdc72

Please sign in to comment.