Ticket #179: xcache-gets.patch

File xcache-gets.patch, 2.8 kB (added by fcicq, 6 months ago)

xcache_gets plugin.

  • .c

    old new  
    18981898    } LEAVE_LOCK(xce.cache); 
    18991899} 
    19001900/* }}} */ 
     1901/* {{{ proto mixed xcache_gets(array name, [array &failed_items]) 
     1902   Get cached data by specified name in an array. 2008.06 fcicq, many code from PECL-APC. */ 
     1903PHP_FUNCTION(xcache_gets) 
     1904{ 
     1905    xc_entry_t xce, *stored_xce; 
     1906    xc_entry_data_var_t var; 
     1907    HashTable *hash; 
     1908    HashPosition hpos; 
     1909    zval *key; 
     1910    zval *flags = NULL; 
     1911    zval *result; 
     1912    zval **hentry; 
     1913    zval *result_entry; 
     1914    int is_flag_exists; 
     1915 
     1916    if (!xc_var_caches) { 
     1917        VAR_DISABLED_WARNING(); 
     1918        RETURN_NULL(); 
     1919    } 
     1920     
     1921    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z|z", &key, &flags) == FAILURE) { 
     1922        return; 
     1923    } 
     1924 
     1925    is_flag_exists = 0; 
     1926    if (flags != NULL) { 
     1927        is_flag_exists = 1; 
     1928        if (Z_TYPE_P(flags) != IS_ARRAY) { 
     1929            array_init(flags); 
     1930        } 
     1931    } 
     1932         
     1933    if (Z_TYPE_P(key) != IS_ARRAY) { 
     1934        php_error_docref(NULL TSRMLS_CC, E_WARNING, "xcache_gets() expects an array of strings."); 
     1935        RETURN_FALSE; 
     1936    }  
     1937    xce.data.var = &var; 
     1938 
     1939    hash = Z_ARRVAL_P(key); 
     1940    MAKE_STD_ZVAL(result); 
     1941    array_init(result); 
     1942    zend_hash_internal_pointer_reset_ex(hash, &hpos); 
     1943    while(zend_hash_get_current_data_ex(hash, (void**)&hentry, &hpos) == SUCCESS) { 
     1944        if(Z_TYPE_PP(hentry) != IS_STRING) { 
     1945            php_error_docref(NULL TSRMLS_CC, E_WARNING, "xcache_gets() expects an array of strings."); 
     1946            RETURN_FALSE; 
     1947        } 
     1948        xc_entry_init_key_var(&xce, *hentry TSRMLS_CC); 
     1949 
     1950        ENTER_LOCK(xce.cache) { 
     1951            stored_xce = xc_entry_find_dmz(&xce TSRMLS_CC); 
     1952            if (stored_xce) { 
     1953                if (!VAR_ENTRY_EXPIRED(stored_xce)) { 
     1954                    MAKE_STD_ZVAL(result_entry); 
     1955 
     1956                    xc_processor_restore_zval(result_entry, stored_xce->data.var->value, stored_xce->have_references TSRMLS_CC); 
     1957 
     1958                    zend_hash_add(Z_ARRVAL_P(result), Z_STRVAL_PP(hentry), Z_STRLEN_PP(hentry) +1, &result_entry, sizeof(zval*), NULL); 
     1959                    xce.cache->hits ++; 
     1960                } else { 
     1961                    xc_entry_remove_dmz(stored_xce TSRMLS_CC); 
     1962                    if (is_flag_exists) { 
     1963                        add_next_index_stringl(flags,  Z_STRVAL_PP(hentry), Z_STRLEN_PP(hentry) , 1); 
     1964                    } 
     1965                    xce.cache->misses ++; 
     1966                } 
     1967            } else { 
     1968                if (is_flag_exists) { 
     1969                    add_next_index_stringl(flags,  Z_STRVAL_PP(hentry), Z_STRLEN_PP(hentry) , 1); 
     1970                } 
     1971                xce.cache->misses ++; 
     1972            } 
     1973        } LEAVE_LOCK(xce.cache); 
     1974        zend_hash_move_forward_ex(hash, &hpos); 
     1975    } 
     1976    RETVAL_ZVAL(result, 0, 1); 
     1977} 
     1978/* }}} */ 
    19011979/* {{{ proto bool  xcache_isset(string name) 
    19021980   Check if an entry exists in cache by specified name */ 
    19031981PHP_FUNCTION(xcache_isset) 
     
    23002378    PHP_FE(xcache_inc,               NULL) 
    23012379    PHP_FE(xcache_dec,               NULL) 
    23022380    PHP_FE(xcache_get,               NULL) 
     2381    PHP_FE(xcache_gets,               NULL)  
    23032382    PHP_FE(xcache_set,               NULL) 
    23042383    PHP_FE(xcache_isset,             NULL) 
    23052384    PHP_FE(xcache_unset,             NULL)