Giter VIP home page Giter VIP logo

Comments (9)

apotonick avatar apotonick commented on June 1, 2024

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.

jamesbebbington avatar jamesbebbington commented on June 1, 2024

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.

apotonick avatar apotonick commented on June 1, 2024

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.

dgilperez avatar dgilperez commented on June 1, 2024

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.

apotonick avatar apotonick commented on June 1, 2024

Cool, only 3 years later this got implemented. Thanks @Fractious I basically copied your code to Caching::Notifications.

from cells.

schorsch avatar schorsch commented on June 1, 2024

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.

apotonick avatar apotonick commented on June 1, 2024

@schorsch Yo! Good to see you here!

@timoschilling Hilft!

from cells.

timoschilling avatar timoschilling commented on June 1, 2024

@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.

timoschilling avatar timoschilling commented on June 1, 2024

@schorsch contact me if you need more support

from cells.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.