Comments (9)
We once had this in earlier versions but removed it as nobody seemed to take advantage of this feature. I'd be happy to see a patch, however, maybe we should introduce some cell/debugging.rb
module responsible for mixing in development-specific behaviour into cells (e.g. caching logging, template finding output, etc). If you send a patch for logging I can take care of the rest. Thanks!
from cells.
Assuming we only need to support Rails 3 we can use ActiveSupport::Notifications
(RailsCast).
I had a quick play with it and simply modifying #expire_cache_key
and #render_state
in Cell::Caching::ClassMethods
to include instrumentation seems to do the job:
def expire_cache_key(key, *args)
ActiveSupport::Notifications.instrument("expire_fragment.action_controller", :key => key) do
cache_store.delete(key, *args)
end
end
def render_state(state, *args)
return super(state, *args) unless self.class.cache?(state)
key = self.class.state_cache_key(state, call_state_versioner(state, *args))
options = self.class.cache_options[state]
ActiveSupport::Notifications.instrument("read_fragment.action_controller", :key => key) do
self.class.cache_store.fetch(key, options) do
ActiveSupport::Notifications.instrument("write_fragment.action_controller", :key => key) do
super(state, *args)
end
end
end
end
Note that the instrumentation in #render_state
does result in both a read and write being logged the when the cache is empty, so the logic may want to be changed to conditionally do a cache read or write instead of a fetch.
I wasn't sure how to go about testing this however as I couldn't see any caching tests.
from cells.
Yeah, notifications seem to be a good choice, although I'd like to push stuff like this in a Cell::Debugging module. Cash tests are here: https://github.com/apotonick/cells/blob/master/test/rails/caching_test.rb
from cells.
Hi!
Is the Cell::Debugging module feature going forward? We'd be also interested in having such a logging feature. We just started playing caching our cells and its difficult to understand what is happening without some logging.
Regards!
from cells.
Cool, only 3 years later this got implemented. Thanks @Fractious I basically copied your code to Caching::Notifications
.
from cells.
Do i need to wire the notifications to the log output myself? As the cache output is pretty usefull for a dev.
... yes i finally made it to try cells
from cells.
@schorsch Yo! Good to see you here!
@timoschilling Hilft!
from cells.
@schorsch
Here is a subscribe example for read_fragment.action_controller
and write_fragment.action_controller
ActiveSupport::Notifications.subscribe('read_fragment.action_controller') do |name, start, finish, id, payload|
name # => String, name of the event (such as 'read_fragment.action_controller' from above)
start # => Time, when the instrumented block started execution
finish # => Time, when the instrumented block ended execution
id # => String, unique ID for this notification
payload # => Hash, the payload
Rails.logger.debug "..."
end
from cells.
@schorsch contact me if you need more support
from cells.
Related Issues (20)
- Cells + Airbrake issue - double exceptions raised HOT 2
- Using Cells with Rails engine that has html.erb partials not being picked up HOT 5
- Confusing file structure - views or view? HOT 7
- Template Missing ... again! HOT 21
- how to render erb templates when haml/hamlit and erb extensions installed HOT 3
- Render an array inside view cell HOT 1
- Escaping implementation seems to be a glaring LAYER VIOLATION, methinks.
- Is there some way to do html escaping default with options?
- Publish latest version on Rubygems HOT 10
- should default to file_name.html.erb or .haml HOT 1
- Can't get form_with to work from a cell in Rails 6 HOT 3
- License HOT 1
- Form Input renders as raw text in cell HOT 1
- Feature Request: Support Recyclable Cache Key
- Still maintained? Documentation URLs broken. HOT 9
- Default cache key produces clashes HOT 4
- Options hash is same instance passed to each cell when using collections HOT 1
- Slim v5 breaks cells HOT 9
- Ruby 3.0 ArgumentError: wrong number of arguments error with keyword args for Cell::Testing
- Ruby 3.0 ArgumentError: wrong number of arguments error with Caching
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from cells.