<!--#
Test type 7: Caching
TechEmpower Web Framework Benchmarks
-->
<!--#declaration
#include "world.h"

static UCache* cache;

static void usp_init_cached_worlds()
{
   U_TRACE(5, "::usp_init_cached_worlds()")

   UOrmSession sql_query(U_CONSTANT_TO_PARAM("hello_world"));

   if (sql_query.isReady() == false)
      {
      U_WARNING("usp_init_cached_worlds(): we cound't connect to db");

      return;
      }

   World world_query;
   UOrmStatement stmt_query(sql_query, U_CONSTANT_TO_PARAM("SELECT * FROM World"));

   stmt_query.into(world_query);
   stmt_query.execute();

   // creat and fill the cache

   U_NEW(UCache, cache, UCache);

   (void) cache->open(U_STRING_FROM_CONSTANT("/tmp/ULib_cached_worlds.cache"), 10000 * 64, U_NULLPTR, true);

   do {
      cache->add(world_query.id, world_query.randomNumber);
      }
   while (stmt_query.nextRow());

   World::handlerFork();
}

static void handlerQuery(uint32_t i)
{
   U_TRACE(5, "::handlerQuery(%u)", i)

   U_INTERNAL_ASSERT_POINTER(cache)

   World::rnum = cache->getNumber(World::rnumber[i]);
}
-->
<!--#header
-->
<!--#code
World::doUpdateNoSql(handlerQuery);
-->
