简体   繁体   English

如何在Azure WebRole上正确设置ImageResizer的缓存目录?

[英]How can I properly set the cache directory for ImageResizer on an Azure WebRole?

ImageResizer's DiskCache plugin works fine locally, but when I deploy the WebRole to Azure the deployment partition is too small to cache a meaningful amount of files. ImageResizer的DiskCache插件在本地工作正常,但是当我将WebRole部署到Azure时,部署分区太小而无法缓存大量文件。

Specifically, the WebRole partition is around 1GB on a small role. 具体来说,WebRole分区在一个小角色上约为1GB。 I'd like to point the cache directory to: 我想将缓存目录指向:

  1. The "C:" drive (around 200+GB on a small role). “C:”驱动器(小角色大约200 + GB)。
  2. An attached drive (any size I specify). 附加驱动器(我指定的任何大小)。

The problem is the write privileges necessary for the WebRole. 问题是WebRole所需的写权限。 Is there a simple workaround for a temp directory, or do I need a PowerShell script to configure ACLs on a virtual directory and attach it to the WebRole's site? 是否有临时目录的简单解决方法,或者我是否需要PowerShell脚本来配置虚拟目录上的ACL并将其附加到WebRole的站点?

Before I go down that route I'd like to know if anyone has a reasonable workaround for this. 在我走这条路之前,我想知道是否有人有合理的解决方法。

In ServiceDefinition.csdef: 在ServiceDefinition.csdef中:

<Task commandLine="makevdir.cmd" executionContext="elevated" taskType="background" />

Makevdir.cmd: Makevdir.cmd:

PowerShell -ExecutionPolicy Unrestricted .\makevdir.ps1 >> "%RoleRoot%\makevdir.txt" 2>&1
EXIT /B %errorlevel%

Makevdir.ps1: Makevdir.ps1:

# Make Virtual Directory for ImageResizer DiskCache plugin (/imagecache) 
Write-Host "makevdir.ps1 starting"

# $ImageCacheDir = $env:temp + "\imagecache"
#
# The TEMP paths are quota limited to ~100MB, so use a hard coded path:
$ImageCacheDir = "C:\Resources\AspNetTemp\imagecache"

Write-Host "ImageCacheDir = $ImageCacheDir"
md -Path $ImageCacheDir

# Set the ACL to allow IIS access to the new directory
$acl = Get-Acl $ImageCacheDir
$identity = "IIS_IUSRS"
$fileSystemRights = "Modify"
$inheritanceFlags = "ContainerInherit, ObjectInherit"
$propagationFlags = "None"
$accessControlType = "Allow"
$rule = New-Object System.Security.AccessControl.FileSystemAccessRule($identity,          $fileSystemRights, $inheritanceFlags, $propagationFlags, $accessControlType)
$acl.SetAccessRule($rule)
Set-Acl $ImageCacheDir $acl

# Get the AppName by appending _Web/ to the RoleInstanceID environmental variable
$AppName = $env:RoleInstanceID + "_Web/"
Write-Host "AppName = $AppName"

# Retry creating the virtual directory every five seconds for a maximum of 20 tries
$tries = 0
& $Env:WinDir\system32\inetsrv\appcmd.exe add vdir /app.name:$AppName /path:/imagecache /physicalpath:$ImageCacheDir
while (!$? -and $tries -lt 20) {
$tries++
    sleep 5
& $Env:WinDir\system32\inetsrv\appcmd.exe add vdir /app.name:$AppName /path:/imagecache /physicalpath:$ImageCacheDir
}

Write-Host "makevdir.ps1 exiting"
Exit

As DiskCache delegates the serving of files to IIS for performance, you will need an IIS virtual folder. 由于DiskCache将文件服务委托给IIS以提高性能,因此您需要一个IIS虚拟文件夹。

DiskCache can cache/serve files from any virtual folder, regardless of its physical location (although local storage is best - latency is unacceptable). DiskCache可以从任何虚拟文件夹缓存/提供文件,无论其物理位置如何(尽管本地存储最佳 - 延迟是不可接受的)。

A temp folder won't work, as both IIS and the ASP.NET runtime user accounts need read/write access, and you definitely want DiskCache to be persistent. 临时文件夹不起作用,因为IIS和ASP.NET运行时用户帐户都需要读/写访问权限,并且您肯定希望DiskCache是​​持久的。

It does sound like you'll need to script the setup for this. 听起来你需要为此设置脚本。 I think a lot of people could benefit from such a script, if you can share it when it's done. 我想很多人都可以从这样的脚本中受益,如果你可以在完成后分享它。 Here's how to script an IIS virtual folder . 以下是如何编写IIS虚拟文件夹的脚本

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM