/* :nodoc: */ static mrb_value Cache_init(mrb_state *mrb, mrb_value self) { mrb_value o; mrb_get_args(mrb, "o", &o); lmc_check_dict(mrb, o); lmc_error_t e; rb_lmc_handle_t *h; local_memcache_t *l = local_memcache_create(rstring_ptr_null(mrb_hash_get(mrb, o, lmc_rb_sym_namespace(mrb))), rstring_ptr_null(mrb_hash_get(mrb, o, lmc_rb_sym_filename(mrb))), double_value(mrb, mrb_hash_get(mrb, o, lmc_rb_sym_size_mb(mrb))), size_t_value(mrb_hash_get(mrb, o, lmc_rb_sym_min_alloc_size(mrb))), &e); if (!l) rb_lmc_raise_exception(mrb, &e); h = (rb_lmc_handle_t *)DATA_PTR(self); if (h) { mrb_free(mrb, h); } DATA_TYPE(self) = &lmc_cache_type; DATA_PTR(self) = NULL; h = (rb_lmc_handle_t *)mrb_malloc(mrb, sizeof(rb_lmc_handle_t)); if (!h) { mrb_raise(mrb, E_RUNTIME_ERROR, "memory allocation error"); } h->lmc = l; h->open = 1; DATA_PTR(self) = h; return self; }
/* * call-seq: Cache.drop(*args) * * Deletes a memory pool. If the :force option is set, locked semaphores are * removed as well. * * WARNING: Do only call this method with the :force option if you are sure * that you really want to remove this memory pool and no more processes are * still using it. * * If you delete a pool and other processes still have handles open on it, the * status of these handles becomes undefined. There's no way for a process to * know when a handle is not valid anymore, so only delete a memory pool if * you are sure that all handles are closed. * * valid options for drop are * [:namespace] * [:filename] * [:force] * * The memory pool must be specified by either setting the :filename or * :namespace option. The default for :force is false. */ static mrb_value Cache__drop(mrb_state *mrb, mrb_value self) { mrb_value o; mrb_get_args(mrb, "o", &o); lmc_check_dict(mrb, o); lmc_error_t e; if (!local_memcache_drop_namespace(rstring_ptr_null(mrb_hash_get(mrb, o, lmc_rb_sym_namespace(mrb))), rstring_ptr_null(mrb_hash_get(mrb, o, lmc_rb_sym_filename(mrb))), bool_value(mrb_hash_get(mrb, o, lmc_rb_sym_force(mrb))), &e)) { rb_lmc_raise_exception(mrb, &e); } return mrb_nil_value(); }