Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/amazon-s3/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 是否在后台作业/PDF文档中缓存ActiveStorage图像?_Ruby On Rails_Amazon S3_Rails Activestorage - Fatal编程技术网

Ruby on rails 是否在后台作业/PDF文档中缓存ActiveStorage图像?

Ruby on rails 是否在后台作业/PDF文档中缓存ActiveStorage图像?,ruby-on-rails,amazon-s3,rails-activestorage,Ruby On Rails,Amazon S3,Rails Activestorage,我使用Prawn生成PDF票据,例如,我将插入一个活动存储映像,如下所示: def image_data(attachment) StringIO.new attachment.download end 图像数据(票证模板背景) 但是我注意到一些顾客有很多票,他们都使用相同的图像。ActiveStorage每次都从S3下载映像,因此如果客户有大约10张票据,则下载所有票据时可能会导致超时 我在heroku上,所以即使文件系统不是永久性的,我认为使用磁盘缓存根据需要获取或下载图像也是一个好主

我使用Prawn生成PDF票据,例如,我将插入一个活动存储映像,如下所示:

def image_data(attachment)
  StringIO.new attachment.download
end
图像数据(票证模板背景)

但是我注意到一些顾客有很多票,他们都使用相同的图像。ActiveStorage每次都从S3下载映像,因此如果客户有大约10张票据,则下载所有票据时可能会导致超时

我在heroku上,所以即使文件系统不是永久性的,我认为使用磁盘缓存根据需要获取或下载图像也是一个好主意。但我对添加缓存和引发问题感到紧张

我想添加一个lib类,如下所示:

class ImageCacher

  def self.get(record, attachment)
    ## fetch from disk, or download from S3
  end

end

正在寻找有关实现此功能的提示和想法。

您是如何解决此问题的?