why i can't write anything to a custom cache table?
You don't need to create your own table to use the internal cache. Just use cache_set() and cache_get() as documented. This will store the $my_data in the default 'cache' table:

// Store $my_data in cache.
cache_set($data_id, $my_data);

// Get $my_data from cache.
$data = cache_get($data_id);


Your code snippet should look something like this:

$cid = some_calcuated_cid();
$cache = cache_get($cid);

if (!$cache){
  $data = some_calcuated_data();
  cache_set($cid, $data);
}


Documentation:

cache_set()

cache_get()