Skip to content

Commit

Permalink
Added new CachingTimeOut property to force cache invalidation after t…
Browse files Browse the repository at this point in the history
…he specified number of seconds
  • Loading branch information
jmalarcon committed Apr 25, 2020
1 parent 047ad51 commit 460bd3c
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 13 deletions.
23 changes: 16 additions & 7 deletions src/MIISHandler/MarkdownFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public class MarkdownFile
private string _layout;
private SimpleYAMLParser _FrontMatter;
private bool? _CachingEnabled = null; //Should be default to allow for the expression shortcircuit in the CachingEnabled property
private double _NumSecondsCacheIsValid = 0;
private double _CachingTimeOut = 0;
private bool _isPersistedToCache = false;
#endregion

Expand Down Expand Up @@ -524,18 +524,26 @@ internal bool CachingEnabled
}
}

//The timeout in seconds to force the content cache to invalidate
//Set by custom tags or params. 0 means no time based expiration.
//This is only read once, when persisting the file contents to the Cache
internal double CachingTimeOut
{
get
{
return _NumSecondsCacheIsValid;
//Read from Front-Matter
double fmVal = 0;
_ = double.TryParse(FieldValuesHelper.GetFieldValue("CachingTimeOut", this, "0"), out fmVal);
return Math.Min(_CachingTimeOut, fmVal);
}
set
{
_NumSecondsCacheIsValid = value;
if (value <= 0) _NumSecondsCacheIsValid = 0;
//if (value > 86400) _NumSecondsCacheIsValid = 86400; //24 hours in seconds
if (value <= 0) return;
//If the value has been set before (external value and FM value, for example), the minimum one wins
if (_CachingTimeOut > 0)
_CachingTimeOut = Math.Min(_CachingTimeOut, value);
else
_CachingTimeOut = value;
}
}

Expand Down Expand Up @@ -693,12 +701,13 @@ private void PersistContentToCache()
{
CacheDependency deps = GetCacheDependencies();

double cachingTimeout = this.CachingTimeOut;
//Add to Cache
if (this.CachingTimeOut > 0)
if (cachingTimeout > 0)
{
//Cache invalidation when files change or after a certain time
HttpRuntime.Cache.Insert(this.CachingId, this.CachedContentItem, deps,
DateTime.UtcNow.AddSeconds(this.CachingTimeOut), Cache.NoSlidingExpiration);
DateTime.UtcNow.AddSeconds(cachingTimeout), Cache.NoSlidingExpiration);
}
else
{
Expand Down
4 changes: 2 additions & 2 deletions src/MIISHandler/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,5 @@
//
// You can specify all the values or you can default the Revision and Build Numbers
// by using the '*' as shown below:
[assembly: AssemblyVersion("3.3.0")]
[assembly: AssemblyFileVersion("3.3.0")]
[assembly: AssemblyVersion("3.4.0")]
[assembly: AssemblyFileVersion("3.4.0")]
9 changes: 5 additions & 4 deletions src/Tests/posts/index.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
---
title: Sample folder for Files custom Front-Matter field
author: jmalarcon
posts: !!FilesFromFolder ./ false
tags: !!TagsFromFolder ./ false
categs: !!CategsFromFolder ./ false
caching: true
#posts: !!FilesFromFolder ./ false
#tags: !!TagsFromFolder ./ false
#categs: !!CategsFromFolder ./ false
#caching: true
#CachingTimeout: 60
arr: [cli-ref-config, cli-ref-delete, cli-ref-init]
---

Expand Down

0 comments on commit 460bd3c

Please sign in to comment.