Skip to content

Commit

Permalink
cache embedded files (#35 and #42)
Browse files Browse the repository at this point in the history
  • Loading branch information
lformella committed Apr 8, 2014
1 parent 5f1035d commit 4de8e46
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 12 deletions.
29 changes: 17 additions & 12 deletions XG.Plugin.Webserver/Nancy/CustomBootstrapper.cs
Expand Up @@ -27,6 +27,8 @@
using System.IO;
using System.Linq;
using System.Reflection;
using CacheAspect;
using CacheAspect.Attributes;
using Nancy;
using Nancy.Conventions;
using Nancy.Responses;
Expand Down Expand Up @@ -73,21 +75,24 @@ protected override void ConfigureConventions(NancyConventions nancyConventions)
nancyConventions.StaticContentsConventions.Add(StaticContentConventionBuilder.AddDirectory("Resources", "Resources"));
nancyConventions.StaticContentsConventions.Add(StaticContentConventionBuilder.AddDirectory("Scripts", "Scripts"));
#else
nancyConventions.StaticContentsConventions.Add((ctx, rootPath) =>
nancyConventions.StaticContentsConventions.Add((ctx, rootPath) => GetResource (ctx.Request.Url.Path));
#endif
}

[Cache.Cacheable]
private EmbeddedFileResponse GetResource(string aPath)
{
try
{
try
var directoryName = "XG.Plugin.Webserver" + Path.GetDirectoryName(aPath).Replace(Path.DirectorySeparatorChar, '.').Replace("-", "_");
var fileName = Path.GetFileName(aPath);
if (ResourceExists(directoryName + "." + fileName))
{
var directoryName = "XG.Plugin.Webserver" + Path.GetDirectoryName(ctx.Request.Url.Path).Replace(Path.DirectorySeparatorChar, '.').Replace("-", "_");
var fileName = Path.GetFileName(ctx.Request.Url.Path);
if (ResourceExists(directoryName + "." + fileName))
{
return new EmbeddedFileResponse(GetType().Assembly, directoryName, fileName);
}
return new EmbeddedFileResponse(GetType().Assembly, directoryName, fileName);
}
catch(Exception) {}
return null;
});
#endif
}
catch(Exception) {}
return null;
}
}
}
Expand Down
9 changes: 9 additions & 0 deletions XG.Plugin.Webserver/XG.Plugin.Webserver.csproj
Expand Up @@ -79,6 +79,15 @@
<Reference Include="Newtonsoft.Json">
<HintPath>..\packages\Newtonsoft.Json.6.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
</Reference>
<Reference Include="Microsoft.ApplicationServer.Caching.Client">
<HintPath>..\packages\Cache.1.2.1\Microsoft.ApplicationServer.Caching.Client.dll</HintPath>
</Reference>
<Reference Include="CacheAspect">
<HintPath>..\packages\Cache.1.2.1\CacheAspect.dll</HintPath>
</Reference>
<Reference Include="PostSharp">
<HintPath>..\packages\Cache.1.2.1\PostSharp.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="Nancy\ShutdownModule.cs" />
Expand Down
Binary file added packages/Cache.1.2.1/BplusDotNet.dll
Binary file not shown.
Binary file added packages/Cache.1.2.1/CacheAspect.dll
Binary file not shown.
Binary file added packages/Cache.1.2.1/CacheAspect.pdb
Binary file not shown.
Binary file not shown.
Binary file added packages/Cache.1.2.1/PostSharp.Laos.dll
Binary file not shown.
Binary file added packages/Cache.1.2.1/PostSharp.dll
Binary file not shown.

0 comments on commit 4de8e46

Please sign in to comment.