Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Anyway to clear cache when calling .present? #197

Open
namila opened this issue Apr 21, 2020 · 2 comments
Open

Anyway to clear cache when calling .present? #197

namila opened this issue Apr 21, 2020 · 2 comments

Comments

@namila
Copy link

namila commented Apr 21, 2020

Environment details
ruby 2.6.2
rails 5.1
carrierwave 2.0
carrierwave-mongoid 1.3

Steps to reproduce

take an object which has a file in s3 and call
offer.offer_pdf.present?

expected result : true, actual_result: true

delete that file from the s3 bucket and call the same method again
offer.offer_pdf.present?

expected result: false, actual_result: true

I suspect the result of the "#present?" is cached and the actual state is not reflected when calling it again. Is there any way to clear this cache so I can get the current status of the file?
(I tried calling #reload on the offer object, but still it did not reflect the actual status of the file)
I raised the same question under fog repo, they feel there should be a way to achieve this using CarrierWave (fog/fog#4029)

@leoarnold
Copy link
Contributor

@namila The method #offer_url is not from carrierwave-mongoid. It is defined by carrierwave itself and not overridden by this gem:

https://github.com/carrierwaveuploader/carrierwave/blob/3084b24257dd309ee00ff350067c8c6e985ad1bc/lib/carrierwave/mount.rb#L149-L151

Tracing the method call down to the fog connector leads to the actual implementation:

https://github.com/carrierwaveuploader/carrierwave/blob/3084b24257dd309ee00ff350067c8c6e985ad1bc/lib/carrierwave/storage/fog.rb#L419-L425

tl;dr: When you call offer.offer_url.present? you are not checking whether the actual remote file is available, but merely whether carrierwave was able to generate a URL for the location where the file should be.

@rmm5t Close issue as "3rd party issue"?

@leoarnold
Copy link
Contributor

I just noticed: offer.offer.file.exists? may do the requested.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants