Ejemplo n.º 1
0
/**
 * Records the end of the execution of a query.
 *
 * @since 3.0.0
 *
 * @uses wl_caching_is_response_cached() to determine if the response is cached. Cached responses are ignored.
 *
 * @param string $url     The remote URL.
 * @param string $args    The request parameters.
 * @param string $query   The SPARQL query.
 * @param array $response The response.
 */
function wl_profiling_sparql_post_request($url, $args, $query, $response)
{
    global $wl_profiling_started_at;
    // Ignore cached calls.
    if (function_exists('wl_caching_response_is_cached') && wl_caching_response_is_cached($response)) {
        return;
    }
    $interval = round(microtime(true) * 1000) - $wl_profiling_started_at;
    // Insert the profiling data.
    wl_profiling_insert($query, $interval);
}
Ejemplo n.º 2
0
 function test_caching_expired()
 {
     $url = 'http://example.org/';
     $args = array('method' => 'GET');
     // ensure a previous cache file doesn't exists.
     $hash_0 = wl_caching_hash($url, $args);
     wl_caching_delete($hash_0);
     // Cache for 5 seconds.
     $response_0 = wl_caching_remote_request($url, $args, false, 5);
     #$this->assertFalse( wl_caching_response_is_cached( $response_0 ) );
     // Check that the first request is still cached.
     $response_1 = wl_caching_remote_request($url, $args);
     $this->assertTrue(wl_caching_response_is_cached($response_1));
     // Wait 5 seconds and check that another request is not cached.
     sleep(5);
     $response_2 = wl_caching_remote_request($url, $args);
     $this->assertFalse(wl_caching_response_is_cached($response_2));
 }