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:



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

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



256
257
258
# File 'lib/httpimagestore/configuration/s3.rb', line 256

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

#private_urlObject



240
241
242
243
244
245
246
# File 'lib/httpimagestore/configuration/s3.rb', line 240

def private_url
	url = @cache_file.header['private_url'] and return Addressable::URI.parse(url)
	dirty! :private_url
	url = super
	@cache_file.header['private_url'] = url.to_s
	Addressable::URI.parse(url)
end

#public_urlObject



248
249
250
251
252
253
254
# File 'lib/httpimagestore/configuration/s3.rb', line 248

def public_url
	url = @cache_file.header['public_url'] and return Addressable::URI.parse(url)
	dirty! :public_url
	url = super
	@cache_file.header['public_url'] = url.to_s
	Addressable::URI.parse(url)
end

#read(max_bytes = nil) ⇒ Object



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

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



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

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