Class: Configuration::S3SourceStoreBase::CacheObject

Inherits:
S3Object
  • Object
show all
Extended by:
Stats
Includes:
ClassLogging
Defined in:
lib/httpimagestore/configuration/s3.rb

Instance Method Summary collapse

Methods inherited from S3Object

#s3_object

Constructor Details

#initialize(cache_file, client, bucket, key) {|_self| ... } ⇒ CacheObject

Returns a new instance of CacheObject.

Yields:

  • (_self)

Yield Parameters:



202
203
204
205
206
207
208
209
210
211
212
# File 'lib/httpimagestore/configuration/s3.rb', line 202

def initialize(cache_file, client, bucket, key)
	super(client, bucket, key)

	@cache_file = cache_file
	@dirty = false

	yield self

	# save object if new data was read/written to/from S3 and no error happened
	write_cache if dirty?
end

Instance Method Details

#content_typeObject



247
248
249
# File 'lib/httpimagestore/configuration/s3.rb', line 247

def content_type
	@cache_file.header['content_type'] ||= (dirty! :content_type; super)
end

#private_urlObject



239
240
241
# File 'lib/httpimagestore/configuration/s3.rb', line 239

def private_url
	@cache_file.header['private_url'] ||= (dirty! :private_url; super)
end

#public_urlObject



243
244
245
# File 'lib/httpimagestore/configuration/s3.rb', line 243

def public_url
	@cache_file.header['public_url'] ||= (dirty! :public_url; super)
end

#read(max_bytes = nil) ⇒ Object



214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
# File 'lib/httpimagestore/configuration/s3.rb', line 214

def read(max_bytes = nil)
	begin
		@data = @cache_file.read(max_bytes)
		CacheObject.stats.incr_total_s3_cache_hits
		log.debug{"S3 object cache hit for bucket: '#{@bucket}' key: '#{@key}' [#{@cache_file}]: header: #{@cache_file.header}"}
		return @data
	rescue Errno::ENOENT
		CacheObject.stats.incr_total_s3_cache_misses
		log.debug{"S3 object cache miss for bucket: '#{@bucket}' key: '#{@key}' [#{@cache_file}]"}
	rescue => error
		CacheObject.stats.incr_total_s3_cache_errors
		log.warn "cannot use cached S3 object for bucket: '#{@bucket}' key: '#{@key}' [#{@cache_file}]", error
	end
	@data = super
	dirty! :read
	return @data
end

#write(data, options = {}) ⇒ Object



232
233
234
235
236
237
# File 'lib/httpimagestore/configuration/s3.rb', line 232

def write(data, options = {})
	super
	@data = data
	@cache_file.header['content_type'] = options[:content_type] if options[:content_type]
	dirty! :write
end