<commit_before># $Id$

package EnsEMBL::Web::Controller::Page;

### Prints the main web page - header, footer, navigation etc, and non dynamically loaded content.
### Deals with Command modules if required.

use strict;

use base qw(EnsEMBL::Web::Controller);

sub request   { return 'page'; }
sub cacheable { return 1;      }

sub init {
  my $self    = shift;
  my $hub     = $self->hub;
  my $request = $self->request;
  
  $self->clear_cached_content;
  
  my $cached = $self->get_cached_content($request); # Page retrieved from cache
  
  if (!$cached) {
    return if $self->update_configuration_from_url;                                      # Configuration has been updated - will force a redirect
    return if $self->builder->create_objects($hub->factorytype, $request) eq 'redirect'; # Forcing a redirect - don't need to go any further
  }
  
  $self->update_user_history if $hub->user;
  
  return if $cached;
  
  $self->page->initialize; # Adds the components to be rendered to the page module
  $self->configure;
  $self->render_page;
}

sub render_page {
  my $self = shift;
  $self->SUPER::render_page if $self->access_ok && !$self->process_command;
}

sub clear_cached_content {
  ### Flush the cache if the user has hit ^R or F5.
  ### Removes content from Memcached based on the request's URL and the user's session id.
  
  my $self  = shift;
  my $cache = $self->cache;
  my $r     = $self->r;
  
  if ($cache && ($r->headers_in->{'Cache-Control'} eq 'max-age=0' || $r->headers_in->{'Pragma'} eq 'no-cache') && $r->method ne 'POST') {
    $cache->delete_by_tags($self->{'url_tag'}, $self->{'session_id'} ? "session_id[$self->{'session_id'}]" : ());
    
    warn "DYNAMIC CONTENT CACHE CLEAR: $self->{'url_tag'}, $self->{'session_id'}" if $self->{'cache_debug'};
  }
}

sub update_configuration_from_url {
  ### Checks for shared data and updated config settings from the URL parameters<commit_msg>don't know why we've been checking Pragma all this time, when it doesn't get set by any of our supported browsers<commit_after># $Id$

package EnsEMBL::Web::Controller::Page;

### Prints the main web page - header, footer, navigation etc, and non dynamically loaded content.
### Deals with Command modules if required.

use strict;

use base qw(EnsEMBL::Web::Controller);

sub request   { return 'page'; }
sub cacheable { return 1;      }

sub init {
  my $self    = shift;
  my $hub     = $self->hub;
  my $request = $self->request;
  
  $self->clear_cached_content;
  
  my $cached = $self->get_cached_content($request); # Page retrieved from cache
  
  if (!$cached) {
    return if $self->update_configuration_from_url;                                      # Configuration has been updated - will force a redirect
    return if $self->builder->create_objects($hub->factorytype, $request) eq 'redirect'; # Forcing a redirect - don't need to go any further
  }
  
  $self->update_user_history if $hub->user;
  
  return if $cached;
  
  $self->page->initialize; # Adds the components to be rendered to the page module
  $self->configure;
  $self->render_page;
}

sub render_page {
  my $self = shift;
  $self->SUPER::render_page if $self->access_ok && !$self->process_command;
}

sub clear_cached_content {
  ### Flush the cache if the user has hit ^R or F5.
  ### Removes content from Memcached based on the request's URL and the user's session id.
  
  my $self  = shift;
  my $cache = $self->cache;
  my $r     = $self->r;
  
  if ($cache && $r->headers_in->{'Cache-Control'} =~ /(max-age=0|no-cache)/ && $r->method ne 'POST') {
    $cache->delete_by_tags($self->{'url_tag'}, $self->{'session_id'} ? "session_id[$self->{'session_id'}]" : ());
    
    warn "DYNAMIC CONTENT CACHE CLEAR: $self->{'url_tag'}, $self->{'session_id'}" if $self->{'cache_debug'};
  }
}

sub update_configuration_from_url {
  ### Checks for shared data and updated config settings from the URL parameters
{'fraction_non_alphanumeric': 0.1439180537772087, 'fraction_numerical': 0.0015364916773367477, 'mean_word_length': 3.5471478463329453, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 63, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '235284', 'n_tokens_mistral': 1288, 'n_tokens_neox': 1255, 'n_words': 385}