Is hook_node_view() invoked every time? I wrote a custom module that records page views. So each time a user views a node, it creates an entry in a database table. Essentially I wanted my own custom statistics module. 

The problem is, it's only called once. I would assume some kind of caching is applied to this function. I have this:

function hook_node_view( $node,  $display, $view_mode, $langcode)
{
    $nodeObject = $node['#node'];

    $insert = array(
        'created'    =&gt; REQUEST_TIME,
        'nid'        =&gt; $nodeObject-&gt;id(),
        'uid'        =&gt; \Drupal::currentUser()-&gt;id(),
        'ip'         =&gt; \Drupal::request()-&gt;getClientIp(),
        'session_id' =&gt; session_id(),
    );

    db_insert('node_view_log')
    -&gt;fields($insert)
    -&gt;execute();

}


But it is only called once per node, and not each time the node is viewed. Any idea as to why this is happening? Is there a way to turn of caching for this function only? Or is there perhaps a better place to log page views?
Drupal core provides the statistics module which does basically this. It just maintains a counter and not a record per visit, but that's the basic idea.

And it does that with JS that triggers a callback. The reason it does it like that is that nothing on the server side can reliably do this in many situations. You might have something like varnish in front of your site, then most requests will not even reach your webserver.