Roxen.git / server / base_server / configuration.pike

version» Context lines:

Roxen.git/server/base_server/configuration.pike:1:   // A vitual server's main configuration   // Copyright © 1996 - 2000, Roxen IS.    - constant cvs_version = "$Id: configuration.pike,v 1.334 2000/08/13 00:23:29 per Exp $"; + constant cvs_version = "$Id: configuration.pike,v 1.335 2000/08/13 13:54:21 per Exp $";   constant is_configuration = 1;   #include <module.h>   #include <module_constants.h>   #include <roxen.h>   #include <request_trace.h>      inherit "basic_defvar";      mapping enabled_modules = ([]);   mapping(string:array(int)) error_log=([]);
Roxen.git/server/base_server/configuration.pike:2166:    foreach( query( "URLs" )-registered_urls, string url )    {    registered_urls += ({ url });    roxenp()->register_url( url, this_object() );    }    foreach( registered_urls-query("URLs"), string url )    {    registered_urls -= ({ url });    roxenp()->unregister_url( url );    } +  if( !datacache ) +  datacache = DataCache( ); +  else +  datacache->init_from_variables();   }      void save_me()   {    save_one( 0 );   }      void save(int|void all)   //! Save this configuration. If all is included, save all configuration   //! global variables as well, otherwise only all module variables.
Roxen.git/server/base_server/configuration.pike:2935:    report_error( "While calling after_init_hook %O:\n%s",    q, describe_backtrace( w ) );       after_init_hooks = ({});       inited = 1;    report_notice(LOC_S(4, "All modules for %s enabled in %3.1f seconds") +    "\n\n", query_name(), (gethrtime()-start_time)/1000000.0);   }    +  + // Trivial cache (actually, it's more or less identical to the 200+ + // lines of C in HTTPLoop. But it does not have to bother with the + // fact that more than one thread can be active in it at once. Also, + // it does not have to delay free until all current connections using + // the cache entry is done...) + class DataCache + { +  mapping(string:array(string|mapping(string:mixed))) cache = ([]); +  +  int current_size; +  int max_size; +  int max_file_size; +  +  int hits, misses; +  +  static void clear_some_cache() +  { +  array q = indices( cache ); +  for( int i = 0; i<sizeof( cache)/10; i++ ) +  { +  string ent = q[random(sizeof(q))]; +  current_size -= strlen( cache[ent][0] ); +  m_delete( cache, q[random(sizeof(q))] ); +  } +  } +  +  void expire_entry( string url ) +  { +  if( cache[ url ] ) +  { +  current_size -= strlen(cache[url][0]); +  m_delete( cache, url ); +  } +  } +  +  void set( string url, string data, mapping meta, int expire ) +  { + // if( strlen( data ) > max_file_size ) // checked in conf + // return 0; +  call_out( expire_entry, expire, url ); +  while( (strlen( data ) + current_size) > max_size ) +  clear_some_cache(); +  current_size += strlen( data ); +  cache[url] = ({ data, meta }); +  } +  +  array(string|mapping(string:mixed)) get( string url ) +  { +  mixed res; +  if( res = cache[ url ] ) +  hits++; +  else +  misses++; +  return res; +  } +  +  void init_from_variables( ) +  { +  max_size = query( "data_cache_size" ) * 1024; +  max_file_size = query( "data_cache_file_max_size" ) * 1024; +  while( current_size > max_size ) +  clear_some_cache(); +  } +  +  static void create() +  { +  init_from_variables(); +  } + }; +  + DataCache datacache; +    void create(string config)   {    name=config;    -  +  // for now only theese two. In the future there might be more variables. +  defvar( "data_cache_size", 2048, DLOCALE("", "Data Cache:Cache size"), +  TYPE_INT, +  DLOCALE("", "The size of the data cache used to speed up requests " +  "for commonly requested files, in KBytes")); +  +  defvar( "data_cache_file_max_size", 50, DLOCALE("", "Data Cache:Max file size"), +  TYPE_INT, +  DLOCALE("", "The maximum size of a file that is to be considered for " +  "the cache")); +  +     defvar("default_server", 0, DLOCALE(20, "Default site"),    TYPE_FLAG,    DLOCALE(21, "If true, this site will be selected in preference of "    "other sites when virtual hosting is used and no host "    "header is supplied, or the supplied host header does not "    "match the address of any of the other servers.") );       defvar("comment", "", DLOCALE(22, "Virtual server comment"),    TYPE_TEXT_FIELD|VAR_MORE,    DLOCALE(23, "This text will be visible in the administration "