Blast-Radius Aware AI Code Review for Business-Critical Systems
LiveReview LiveReview Explore LiveReview

UR::Context::AutoUnloadPool - Automatically unload objects when scope ends

Description

       UR Objects retrieved from the database normally live in the object cache for the life of the program.
       When a UR::Context::AutoUnloadPool is instantiated, it tracks every object loaded during its life.  The
       Pool's destructor calls unload() on those objects.

       Changed objects and objects loaded before before the Pool is created will not get unloaded.

Methods

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

           Creates  a  Pool  object.  All UR Objects loaded from the database during this object's lifetime will
           get unloaded when the Pool goes out of scope.

       delete
             $guard->delete();

           Invalidates the Pool object.  No objects are unloaded.  When the Pool later goes  out  of  scope,  no
           objects will be unloaded.

Name

       UR::Context::AutoUnloadPool - Automatically unload objects when scope ends

See Also

       UR::Object, UR::Context

perl v5.38.2                                       2024-06-15                   UR::Context::AutoUnloadPool(3pm)

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

See Also