Cache-FastMmap
view release on metacpan or search on metacpan
FastMmap.xs view on Meta::CPAN
CODE:
mmc_close(cache);
sv_setiv(obj, 0);
void
fc_hash(obj, key);
SV * obj;
SV * key;
INIT:
int key_len;
void * key_ptr;
MU32 hash_page, hash_slot;
STRLEN pl_key_len;
FC_ENTRY
PPCODE:
/* Get key length, data pointer */
key_ptr = (void *)SvPV(key, pl_key_len);
key_len = (int)pl_key_len;
/* Hash key to get page and slot */
mmc_hash(cache, key_ptr, key_len, &hash_page, &hash_slot);
XPUSHs(sv_2mortal(newSViv((IV)hash_page)));
XPUSHs(sv_2mortal(newSViv((IV)hash_slot)));
NO_OUTPUT int
fc_lock(obj, page);
SV * obj;
UV page;
INIT:
FC_ENTRY
CODE:
RETVAL = mmc_lock(cache, (MU32)page);
POSTCALL:
if (RETVAL != 0) {
croak("%s", mmc_error(cache));
}
NO_OUTPUT int
fc_unlock(obj);
SV * obj;
INIT:
FC_ENTRY
CODE:
RETVAL = mmc_unlock(cache);
POSTCALL:
if (RETVAL != 0) {
croak("%s", mmc_error(cache));
}
int
fc_is_locked(obj)
SV * obj;
INIT:
FC_ENTRY
CODE:
/* Write value to cache */
RETVAL = mmc_is_locked(cache);
OUTPUT:
RETVAL
void
fc_read(obj, hash_slot, key)
SV * obj;
U32 hash_slot;
SV * key;
INIT:
int key_len, val_len, found;
void * key_ptr, * val_ptr;
MU32 expire_on = 0;
MU32 flags = 0;
STRLEN pl_key_len;
SV * val;
FC_ENTRY
PPCODE:
/* Get key length, data pointer */
key_ptr = (void *)SvPV(key, pl_key_len);
key_len = (int)pl_key_len;
/* Get value data pointer */
found = mmc_read(cache, (MU32)hash_slot, key_ptr, key_len, &val_ptr, &val_len, &expire_on, &flags);
/* If not found, use undef */
if (found == -1) {
val = &PL_sv_undef;
} else {
/* Cached an undef value? */
if (flags & FC_UNDEF) {
val = &PL_sv_undef;
} else {
/* Create PERL SV */
val = sv_2mortal(newSVpvn((const char *)val_ptr, val_len));
/* Make UTF8 if stored from UTF8 */
if (flags & FC_UTF8VAL) {
SvUTF8_on(val);
}
}
flags = flags & ~(FC_UTF8KEY | FC_UTF8VAL | FC_UNDEF);
}
XPUSHs(val);
XPUSHs(sv_2mortal(newSViv((IV)flags)));
XPUSHs(sv_2mortal(newSViv((IV)!found)));
XPUSHs(sv_2mortal(newSViv((IV)expire_on)));
int
fc_write(obj, hash_slot, key, val, expire_on, in_flags)
( run in 0.638 second using v1.01-cache-2.11-cpan-39bf76dae61 )