• Decrease Text SizeIncrease Text Size

Caching Content In Centralpoint

Posted Date: 5/3/2023
    Printer Friendly Version   Email A Friend   Add This   Increase Text Size   Decrease Text Size



CpContent ac = CpContent.GetCache("SDKDefault") as CpContent;
if (ac == null)
{
	ac = new CpContent("SDKDefault");
	ac.AddRelation("IpManager", "StartDate, EndDate, Title, Action");
	ac.InsertCache();
	lblRetrieved.Text = " Database";
}
else  
    lblRetrieved.Text = " Cache"; 

dgContent.DataSource = ac;
dgContent.DataBind();



Caching using filters


SystemFilterOptions sfo = SystemFilterOptions.Audience | SystemFilterOptions.Date | SystemFilterOptions.Enabled;
if (this.User.IsAuthenticated || (this.ModulePage.AbstractType == Modules.Page.AbstractTypes.None)) sfo |= SystemFilterOptions.Role;

string key = "PoliciesAndProcedures.ProceduralManuals";
CpContent content = CpContent.GetCache(key, sfo);
//content = null;
DataTable proceduralManuals;
if (content == null)
{
	string filter = String.Empty;

	content = new CpContent(key, sfo);
	proceduralManuals = content.AddRelation("ProceduralManuals", "DataId, AutoNumber, ModifyDate, StartDate, EndDate, IsEnabled, Title, Target, Summary, ManualNumber, CoverImage", "Title", filter);
	content.InsertCache();
}
else
	proceduralManuals = content.Relation("ProceduralManuals");



This method loads and caches an audience data table.


DataTable dt = HttpContext.Current.Cache.Get("Audiences") as DataTable;
if (dt != null) return dt;

using (SqlConnection connection = new SqlConnection(Management.Application.SelectConnectionString))
{
	connection.Open();
	dt = new DataTable("cpsys_Audiences");
	string sql = String.Format("SELECT {0}.AudienceId, {0}.ParentAudienceId, {0}.SystemName, {0}.[Name], {0}.Description, {0}.IntegrationId, {0}.Properties, {0}.CreateDate, {0}.ModifyDate FROM {0} ORDER BY {0}.[Name]", "dbo.cpsys_Audiences");
	HttpContext.Current.Trace.Write("Audiences Sql", sql);
	SqlCommand command = new SqlCommand(sql, connection);
	SqlDataAdapter adapter = new SqlDataAdapter(command);
	adapter.Fill(dt);
	HttpContext.Current.Cache.Insert("cpsys_Audiences", dt);
}
return dt;
using GetOrCreateByModule


public static DataView GetTenantsA(string connectionString)
{
	string key = "GetTenantsA";
	string moduleSystemName = "TenantsA";
	DataView tenantsA = HttpContext.Current.Cache.GetOrCreateByModule(key, () =>
	{
		string sql = "SELECT DataId, IntegrationId  FROM cpsys_DataCurrent WHERE ModuleId='e086109c-d1b1-4570-b3d3-ee47f5487426' AND IntegrationId <>''";

		DataTable dtIds = Utilities.Database.GetDataTable(key, sql, connectionString);

		DataView dv = dtIds.DefaultView;
		dv.Sort = "IntegrationId";
		return dv;
	}, moduleSystemName);

	return tenantsA;
}


GetNavigationItem and/or GetModule

//GetNavigationItem
 var template = HttpContext.Current.Cache.GetNavigationItem("AdamWellnessTools", null).Attributes;

//GetModule
Guid moduleId = new Guid("0ac63c91-bc47-47ea-9c8b-61e3cb3311ca");
var moduleAttributes = HttpContext.Current.Cache.GetModule(moduleId ).Attributes;


Keywords: Caching Content In Centralpoint



Related Taxonomy

Comments:

Be the first to leave a comment.
Please Login to post comments.