Skip to content

Instantly share code, notes, and snippets.

@steviemcg
Last active January 15, 2018 16:35
Show Gist options
  • Select an option

  • Save steviemcg/b3af1c4613796c8d21a6e1b691bb5abd to your computer and use it in GitHub Desktop.

Select an option

Save steviemcg/b3af1c4613796c8d21a6e1b691bb5abd to your computer and use it in GitHub Desktop.
Brian Pedersen's Cache.aspx - 8.2 Compatible - found at https://briancaos.wordpress.com/2017/05/01/sitecore-caching-clear-caches-individually/
<%@ Page Language="c#" EnableEventValidation="false" AutoEventWireup="true" EnableViewState="false" %>
<%@ Import Namespace="Sitecore.Caching" %>
<script runat="server">
void Page_Load(object sender, System.EventArgs e)
{
if (!Sitecore.Context.IsAdministrator)
{
Response.Write("Must be logged in as an administrator");
Response.End();
return;
}
Response.Buffer = false;
Response.BufferOutput = false;
DataBind();
}
IOrderedEnumerable<ICacheInfo> Caches
{
get
{
return CacheManager.GetAllCaches().OrderBy(c => c.Name);
}
}
double PercentageUsed(ICacheInfo cache)
{
if (cache.MaxSize == 0)
return 0;
return Math.Round(cache.Size / (double)cache.MaxSize * 100, 0);
}
string PercentageColor(double percentage)
{
if (percentage >= 0 && percentage <= 50)
return "green";
if (percentage >= 50 && percentage <= 75)
return "orange";
return "red";
}
private void repCaches_Command(object source, RepeaterCommandEventArgs e)
{
switch (e.CommandName)
{
case "ClearCache":
string cacheName = e.CommandArgument as string;
ICache cache = CacheManager.FindCacheByName(cacheName);
cache.Clear();
repCaches.DataBind();
break;
}
}
long TotalMaxSize()
{
long ac = 0;
foreach (var cache in Caches)
ac = ac + cache.MaxSize;
return ac;
}
long TotalSize()
{
long ac = 0;
foreach (var cache in Caches)
ac += cache.Size;
return ac;
}
double TotalPercentageUsed()
{
if (TotalMaxSize() == 0)
return 0;
return Math.Round((TotalSize() / (double)TotalMaxSize() * 100), 1);
}
</script>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<html>
<head>
<title>Cache Plus</title>
<style type="text/css">
body {
font: normal 12pt arial, verdana;
padding: 20px;
}
.box {
padding: 20px;
margin: 20px;
border: solid 1px black;
background-color: #efefef;
}
input {
height: 30px;
width: 100px;
}
td {
border-bottom: solid 1px #aaa;
padding-right: 20px;
padding-left: 5px;
padding-top: 5px;
padding-bottom: 5px;
}
table {
width: 100%;
}
thead td {
font-weight: bold;
border-bottom: solid 1px #aaa;
padding-right: 20px;
}
</style>
</head>
<body style="font-size: 14px">
<form runat="server">
<div style="padding: 20px; background-color: #eaeaea; border-bottom: solid 1px #777777; font-size: 16px">
<%# Sitecore.StringUtil.GetSizeString(TotalSize()) %> of <%# Sitecore.StringUtil.GetSizeString(TotalMaxSize()) %> used <strong>(<%# TotalPercentageUsed() %>%)</strong>
</div>
<asp:Repeater ID="repCaches" runat="server" EnableViewState="false" OnItemCommand="repCaches_Command" DataSource="<%# Caches %>" ItemType="Sitecore.Caching.ICacheInfo">
<HeaderTemplate>
<table>
<thead>
<tr>
<td>Name</td>
<td></td>
<td>Size</td>
<td>MaxSize</td>
<td>% Used</td>
</tr>
</thead>
</HeaderTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
<ItemTemplate>
<tr>
<td style="width: 250px">
<%# Item.Name %>
</td>
<td style="width: 100px">
<asp:Button ID="btnClearCache" runat="server" CommandArgument="<%# Item.Name %>" CommandName="ClearCache" Text="Clear Cache" />
</td>
<td style="text-align: right; width: 80px">
<%# Sitecore.StringUtil.GetSizeString(Item.Size) %>
</td>
<td style="text-align: right; width: 80px">
<%# Sitecore.StringUtil.GetSizeString(Item.MaxSize) %>
</td>
<td>
<div style="width: <%# PercentageUsed(Item) %>%; height: 30px; background-color: <%# PercentageColor(PercentageUsed(Item)) %>; float: left;"></div>
<div style="width: <%# (100 - PercentageUsed(Item)) %>%; height: 30px; background-color: #ccffcc; float: left;"></div>
</td>
</tr>
</ItemTemplate>
</asp:Repeater>
</form>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment