Conver...Cached(3pm)

✨ NAME ✨

okay so bestie, this is Convert::Binary::C::Cached β€” it's literally just Caching for Convert::Binary::C. it's a Perl module, it's in section 3pm of your manual, and it's here to save you from re-parsing the same C headers over and over like a fool πŸ’…


🌸 SYNOPSIS 🌸

  use Convert::Binary::C::Cached;
  use Data::Dumper;

  #------------------------
  # Create a cached object
  #------------------------
  $c = Convert::Binary::C::Cached->new(
         Cache   => '/tmp/cache.c',
         Include => [
           '/usr/lib/gcc/x86_64-pc-linux-gnu/10.2.0/include',
           '/usr/lib/gcc/x86_64-pc-linux-gnu/10.2.0/include-fixed',
           '/usr/include',
         ],
       );

  #----------------------------------------------------
  # Parse 'time.h' and dump the definition of timespec
  #----------------------------------------------------
  $c->parse_file('time.h');

  print Dumper($c->struct('timespec'));

like. look at her. making an object with a Cache, pointing Include at your actual GCC headers, parsing time.h, dumping timespec. iconic behavior, no notes πŸŽ€


πŸ¦‹ DESCRIPTION πŸ¦‹

so Convert::Binary::C::Cached simply adds caching capability to Convert::Binary::C. that's the whole plot. you use it exactly the same way you'd use Convert::Binary::C β€” the interface is exactly the same. no new tricks to learn, bestie, it's giving "same girl, new dress" ✨

to actually get the caching behavior though, you must pass the Cache option to the constructor. no Cache option? you don't get a cached object, you just get an ordinary Convert::Binary::C object. surprise 🫢 the argument you hand to the Cache option is the file that is used for caching this object.

and here's the cute part: the caching algorithm is smart enough to automatically detect when the cache file cannot be used and the original code has to be parsed instead. when that happens, the cache file gets updated. the update can be triggered by one or more of these factors:

  • the cache file doesn't exist. obvious. πŸ’€
  • the cache file is corrupt, aka it can't be parsed. πŸ’€
  • the object's configuration has changed. πŸ”„
  • the embedded code for a parse method call has changed. πŸ”„
  • at least one of the files that the object depends on either doesn't exist, or has a different size, or a different modification timestamp, or a different change timestamp. πŸ‘€
bestie. reread that last one. size AND timestamps. if neither moved, she's not gonna notice. foreshadowing for LIMITATIONS, iykyk.

🌈 LIMITATIONS 🌈

okay real talk, here's the tea β˜•

you cannot call parse or parse_file more than once when using a Convert::Binary::C::Cached object. once. that's it. that's the deal. honestly not a big problem though, because you usually don't call them multiple times anyway 🀷

and the other thing: if a dependency file changes, but the change affects neither the size nor the timestamps of that file, the caching algorithm cannot detect that an update is required. so like, same size, same timestamps, different content? she will not catch it. that's just how it is, no cap 😭


Copyright (c) 2002-2024 Marcus Holland-Moritz. All rights reserved.

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

like, legal queen behavior. respect πŸ‘‘


πŸ‘‘ SEE ALSO πŸ‘‘

  • See Convert::Binary::C.

that's the whole family tree. go say hi 🫢


and that's the page, bestie!! this was perl v5.42.3, dated 2026-08-20, and you just read Convert...Cached(3pm) β€” go forth and cache responsibly βœ¨πŸŽ€πŸ¦‹πŸ’–

πŸ“¦ where this page comes from