gpt4 book ai didi

amazon-web-services - Amazon S3 - 当文件被 s3cmd 删除时,ColdFusion 的 fileExists 中断

转载 作者:行者123 更新时间:2023-12-04 08:11:16 24 4
gpt4 key购买 nike

我在 ColdFusion 9 上运行一个站点,该站点将缓存信息存储在 Amazon S3 上。

ColdFusion 应用程序构建文件并将它们放入 Amazon S3。每 N 小时,缓存就会被一个执行 s3cmd del 的 bash 脚本刷新,因为它比 ColdFusion 的 fileDelete 更有效目录删除.

但是,在文件被 s3cmd 删除后,ColdFusion 仍会将其标记为现有文件,即使它无法读取其内容。

对于 ColdFusion 应用程序,我在 Application.cfc 上提供了 S3 凭据,它们与 s3cmd 使用的身份验证 key 相同,因此我认为这不是用户权限问题。

让我们来看看这个过程:

// Create an S3 directory with 3 files
fileWrite( myBucket & 'rabbits/bugs-bunny.txt', 'Hi there, I am Bugs Bunny' );
fileWrite( myBucket & 'rabbits/peter-rabbit.txt', 'Hi there, I am Peter Rabbit' );
fileWrite( myBucket & 'rabbits/roger-rabbit.txt', 'Hi there, I am Roger Rabbit' );

writeDump( var = directoryList(myBucket & 'rabbits/', 'true', 'name' ), label = 'Contents of the rabbits/ folder on S3' );

enter image description here

// Delete one of the files with ColdFusion's fileDelete
fileDelete( myBucket & 'rabbits/roger-rabbit.txt' );

writeDump( var = directoryList(myBucket & 'rabbits/', 'true', 'name' ), label = 'Contents of the rabbits/ folder on S3' );

enter image description here

// Now, let's delete a file using the command line:
[~]$ s3cmd del s3://myBucket/rabbits/peter-rabbit.txt
File s3://myBucket/rabbits/peter-rabbit.txt deleted

writeDump( var = directoryList(myBucket & 'rabbits/', 'true', 'name' ), label = 'Contents of the rabbits/ folder on S3' );

enter image description here

// So far, so good!
// BUT!... ColdFusion still thinks that peter-rabbit.txt exists, even
// though it cannot display its contents

writeOutput( 'Does bugs-bunny.txt exist?: ' & fileExists(myBucket & 'rabbits/bugs-bunny.txt') );
writeOutput( 'Then show me the content of bugs-bunny.txt: ' & fileRead(myBucket & 'rabbits/bugs-bunny.txt') );

writeOutput( 'Does peter-rabbit.txt exist?: ' & fileExists(myBucket & 'rabbits/peter-rabbit.txt') );
writeOutput( 'Then show me the content of peter-rabbit.txt: ' & fileRead(myBucket & 'rabbits/peter-rabbit.txt') );
// Error on fileRead(peter-rabbit.txt) !!!

enter image description here

最佳答案

我同意@MarkAKruger 的评论,这里的问题是延迟。

鉴于 ColdFusion 无法始终如一地判断文件是否存在,但它确实始终如一地读取其最新内容(并且在它们不可用时始终无法读取),我想出了这个解决方案:

string function cacheFileRead(
required string cacheFileName
){
var strContent = '';

try{
strContent = FileRead( ARGUMENTS.cachefileName );
}catch(Any e){
strContent = '';
}

return strContent;
}

关于amazon-web-services - Amazon S3 - 当文件被 s3cmd 删除时,ColdFusion 的 fileExists 中断,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27226803/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com