Elastic-Model
view release on metacpan or search on metacpan
lib/Elastic/Manual/Scoping.pod view on Meta::CPAN
=head1 Warning
Scoping is an advanced topic - don't worry about L<Elastic::Model::Scope> until
you need it.
=head1 USES FOR Elastic::Model::Scope
L<Elastic::Model::Scope> acts as an in-memory cache, and serves three
futher purposes:
=head2 Keep weak-ref Elastic::Doc attributes alive
If you have a C<$post> object which has a C<user> attribute, and a C<$user>
object with a C<posts> attribute, then you will want to make (eg) the
C<< $posts->user >> attribute a
L<weak ref|https://metacpan.org/module/Moose::Manual::Attributes#Weak-references>
to avoid circular references.
But then you would have a problem:
sub add_post_to_user {
lib/Elastic/Model/Scope.pm view on Meta::CPAN
}
1;
=pod
=encoding UTF-8
=head1 NAME
Elastic::Model::Scope - Keeps objects alive and connected
=head1 VERSION
version 0.52
=head1 DESCRIPTION
L<Elastic::Model::Scope> is an optional in-memory cache, which serves three
purposes:
=over
=item *
Keep weak-ref L<Elastic::Doc> attributes alive
=item *
Reuse L<Elastic::Doc> objects as singletons.
=item *
Multiple scopes allow you to have multiple versions of L<Elastic::Doc> objects
live at the same time.
lib/Elastic/Model/Scope.pm view on Meta::CPAN
Object C<$one> is now in C<$scope_1> AND C<$scope_2>.
$three = $domain->get( user => 123 );
print $three->name;
# John
print refaddr($one) == refaddr($three) ? 'TRUE' : 'FALSE';
# TRUE
Object C<$two> still exists, and is still kept alive, but will no longer be
returned from C<$scope_2>.
print $two->name;
# Clint
=head2 delete_object()
$scope->delete_object( $ns_name, $uid );
When calling L<Elastic::Model::Role::Model/delete_doc()>,
lib/Elastic/Model/Scope.pm view on Meta::CPAN
This software is copyright (c) 2015 by Clinton Gormley.
This is free software; you can redistribute it and/or modify it under
the same terms as the Perl 5 programming language system itself.
=cut
__END__
# ABSTRACT: Keeps objects alive and connected
t/50_scope/02_store.t view on Meta::CPAN
# Save on older scope with inflated in newer scope
undef $scope_2;
isa_ok $scope_2 = $model->new_scope, 'Elastic::Model::Scope',
'Scope_2 renewed';
isa_ok $u2 = $domain->get( user => 1 ), 'MyApp::User', 'U2 in new scope';
is $u2->name, 'Mary', 'Force U2 inflation';
$u1->name('Felix');
ok $u1->save, 'U1 updated';
compare( "U1-updated and U2-inflate", $u1, $u2, 0, 0 );
# Older version still alive
weaken $u2;
ok $u2, 'Weakened U2 still exists';
# Newer version now current version
isa_ok $u2 = $domain->get( user => 1 ), 'MyApp::User', 'U2 in saved scope';
compare( "U1-saved and U2-same-scope", $u1, $u2, 'same_obj' );
# Done
done_testing;
( run in 0.902 second using v1.01-cache-2.11-cpan-39bf76dae61 )