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

Ability to manually remove single class cache entry #9560

Closed
wants to merge 1 commit into from
Closed

Ability to manually remove single class cache entry #9560

wants to merge 1 commit into from

Conversation

inossidabile
Copy link
Contributor

Sometimes within specs it might be useful to substitute particular controller class. However Rails caches its instance if it was already queried before. So the trick won't work. Currently it's only possible to clear up all the cache at once. Let's add tiny method that allows deletion of particular key. It might be useful for other ClassCache users too as well.

@senny
Copy link
Member

senny commented Mar 6, 2013

Can you post a the use-case, which uses the new method?

@inossidabile
Copy link
Contributor Author

At WashOut specs I need to substitute WSDL serving controller. I do that using remove_const method. However Rails cache it's instance inside Reference. I don't want to clear it completely cause I know exact class that did change but I don't have straight API to do that.

Here's what I do atm:

https://github.com/inossidabile/wash_out/blob/master/spec/spec_helper.rb#L43

Since we already have a way to purge the cache completely why not give ability to purge it partially?

@senny
Copy link
Member

senny commented Mar 6, 2013

I was curious to see how it's being used. As you can see the class ClassCache has no documentation. I think it is an internal class, which should not be accessed directly. To put it differently. This code can could change because we decide to refactor stuff. That's why I'm hesitant to add methods not used by the framework itself but targeting the user.

This is just my opinion though, let's wait what @carlosantoniodasilva @rafaelfranca have to say.

@inossidabile
Copy link
Contributor Author

@senny I understand that for sure. However the absence of documentation and code privacy status doesn't make my task disappear 💃. If I get it right – there are no public ways to affect internal constantization cache. But it is required from time to time.

@senny
Copy link
Member

senny commented Mar 6, 2013

I just wanted to express that if adding this new method is as brittle as the solution you already have (because it might break on refactorings). I'm in favor of your current solution even if it is a hack (you could also monkey-patch the delete method in).

@JonRowe
Copy link
Contributor

JonRowe commented Jan 19, 2014

Was wether this should be merged ever resolved @senny?

@pixeltrix
Copy link
Contributor

@JonRowe no, this is definitely not something that should be merged - ClassCache is an internal implementation detail and there are much better ways to do what the original reporter needs.

@pixeltrix pixeltrix closed this Jan 19, 2014
@inossidabile
Copy link
Contributor Author

@pixeltrix like what for instance?

@pixeltrix
Copy link
Contributor

Create a mock API controller and use that, e.g. washout :mock_api

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

Successfully merging this pull request may close these issues.

None yet

4 participants