Roxen.git / server / base_server / roxen.pike

version» Context lines:

Roxen.git/server/base_server/roxen.pike:1:   // This file is part of Roxen WebServer.   // Copyright © 1996 - 2009, Roxen IS.   //   // The Roxen WebServer main program.   //   // Per Hedbor, Henrik Grubbström, Pontus Hagland, David Hedbor and others.   // ABS and suicide systems contributed freely by Francesco Chemolli    - constant cvs_version="$Id: roxen.pike,v 1.1047 2009/11/23 16:52:01 grubba Exp $"; + constant cvs_version="$Id: roxen.pike,v 1.1048 2009/11/23 17:21:22 grubba Exp $";      //! @appears roxen   //!   //! The Roxen WebServer main program.      // The argument cache. Used by the image cache.   ArgCache argcache;      // Some headerfiles   #define IN_ROXEN
Roxen.git/server/base_server/roxen.pike:4188:    Thread.Mutex mutex = Thread.Mutex();    // Allow recursive locks, since it's normal here.   # define LOCK() mixed __ = mutex->lock (2)      #ifdef ARGCACHE_DEBUG   #define dwerror(ARGS...) werror(ARGS)   #else   #define dwerror(ARGS...) 0   #endif    +  //! Cache of the latest entries requested or stored. +  //! Limited to @[CACHE_SIZE] (currently @expr{900@}) entries.    protected mapping(string|int:mixed) cache = ([ ]);    -  +  //! Cache of cache-ids that have no expiration time. +  //! This cache is maintained in sync with @[cache]. +  //! Note that entries not in this cache may still have +  //! unlimited expiration time. +  protected mapping(string|int:int) no_expiry = ([ ]); +     protected void setup_table()    {    // New style argument2 table.    if(catch(QUERY("SELECT id FROM "+name+"2 LIMIT 0")))    {    master()->resolv("DBManager.is_module_table")    ( 0, "local", name+"2",    "The argument cache, used to map between "    "a unique string and an argument mapping" );    catch(QUERY("DROP TABLE "+name+"2" ));
Roxen.git/server/base_server/roxen.pike:4264:    background_run(wait, cleanup_process);       do_cleanup();    }       protected void init_db()    {    // Delay DBManager resolving to before the 'roxen' object is    // compiled.    cache = ([]); +  no_expiry = ([]);    db = dbm_cached_get("local");    setup_table( );       // Cleanup exprired entries on start.    background_run( 10, cleanup_process );    }       protected void create( string _name )    {    name = _name;
Roxen.git/server/base_server/roxen.pike:4378:       string store( mapping args, int|void timeout )    //! Store a mapping (of purely encode_value:able data) in the    //! argument cache. The string returned is your key to retrieve the    //! data later.    //!    //! @param timeout    //! Timeout for the entry in seconds from now. If @expr{UNDEFINED@},    //! the entry will not expire.    { -  args += ([]); +     if (!zero_type(timeout)) timeout += time();    string encoded_args = encode_value_canonic( args );    string id = Gmp.mpz(Crypto.SHA1.hash(encoded_args), 256)->digits(36);    if( cache[ id ] ) { -  +  if (!no_expiry[id]) { +  // The cache id may have a timeout.    if (zero_type(timeout)) { -  // No timeout. +  // No timeout now, but there may have been one earlier.    QUERY("UPDATE LOW_PRIORITY "+name+"2 "    " SET timeout = NULL " -  " WHERE id = %s", id); +  " WHERE id = %s " +  " AND timeout IS NOT NULL", id); +  no_expiry[id] = 1;    } else { -  +  // Attempt to bump the timeout.    QUERY("UPDATE LOW_PRIORITY "+name+"2 "    " SET timeout = %d "    " WHERE id = %s "    " AND timeout IS NOT NULL "    " AND timeout < %d",    timeout, id, timeout);    } -  +  }    return id;    }    create_key(id, encoded_args, timeout); -  if( sizeof( cache ) >= CACHE_SIZE ) +  if( sizeof( cache ) >= CACHE_SIZE ) {    cache = ([]); -  if( !cache[ id ] ) -  cache[ id ] = args; +  no_expiry = ([]); +  } +  if( !cache[ id ] ) { +  cache[ id ] = args + ([]); +  } +  if (zero_type(timeout)) { +  no_expiry[ id ] = 1; +  }    return id;    }          mapping lookup( string id )    //! Recall a mapping stored in the cache.    {    if( cache[id] )    return cache[id] + ([]);    string encoded_args = (read_encoded_args(id, 0) ||    plugins_read_encoded_args(id));    if(!encoded_args) {    error("Requesting unknown key (not found in db)\n");    }    mapping args = decode_value(encoded_args); -  if( sizeof( cache ) >= CACHE_SIZE ) +  if( sizeof( cache ) >= CACHE_SIZE ) {    // Yowza! Garbing bulldoze style. /mast    cache = ([]); -  +  no_expiry = ([]); +  }    cache[id] = args + ([]);    return args;    }       void delete( string id )    //! Remove the data element stored under the key @[id].    {    LOCK();    (plugins->delete-({0}))( id );    m_delete( cache, id );