UR::Co...oadPool(3pm)

πŸ“¦
version 0.470 Β· 2 versions
, in debian bookworm, ubuntu jammy, ubuntu noble

✨ NAME ✨

UR::Context::AutoUnloadPool β€” the module that auto-unloads your objects the second the scope ends, bestie πŸ’…


πŸŽ€ SYNOPSIS πŸŽ€

my $not_unloaded = Some::Class->get(...);
do {
  my $guard = UR::Context::AutoUnloadPool->create();
  my $object = Some::Class->get(...);  # load an object from the database
  ...                                  # load more things
};  # $guard goes out of scope - unloads objects

πŸ¦‹ DESCRIPTION πŸ¦‹

okay so here's the tea β˜• β€” UR Objects you pull out of the database normally just vibe in the object cache for the entire life of the program. Forever. No cap. They never leave. πŸ™ˆ

But when you instantiate a UR::Context::AutoUnloadPool, it starts tracking every single object loaded during its lifetime. Then the Pool's destructor hits unload() on all of them. Cleanup era. ✨

Two things that do NOT get unloaded, and this is important:

  • objects that were changed 🚫
  • objects that got loaded before the Pool was created 🚫

πŸ’– METHODS πŸ’–

🌸 create

my $guard = UR::Context::AutoUnloadPool->create();

Makes you a Pool object, periodt. Every UR Object loaded from the database during this object's lifetime is getting unloaded when the Pool goes out of scope. That's the whole job and it does it flawlessly, honestly iconic πŸ‘‘

πŸ“ delete

$guard->delete();

Invalidates the Pool object. No objects are unloaded. πŸ’€ So when the Pool later goes out of scope, nothing gets unloaded either. It's giving "never mind, we're keeping all of it." Not me undoing my own cleanup πŸ™ˆ


🌈 SEE ALSO 🌈

  • UR::Object
  • UR::Context

iykyk 🫢


perl v5.32.1 Β· 2022-01-17 β€” that's the source, version and date of this lil gem, bestie. go forth and unload responsibly πŸ’œπŸ§šβ­

πŸ“¦ where this page comes from