DBIx-SQLEngine
view release on metacpan or search on metacpan
SQLEngine/Record/Cache.pm view on Meta::CPAN
my $tablename = $self->table->name;
my $criteria = { $id_col => $record->{ $id_col } };
my %index = ( where => { $id_col => $record->{ $id_col } }, limit => 1, table => $self->table->name );
$self->cache_set( \%index, DBIx::SQLEngine::Record::Set->new($record) );
}
}
########################################################################
########################################################################
=head1 EDITING DATA (SQL DML)
=head2 Insert to Add Records
After constructing a record with one of the new_*() methods, you may save any changes by calling insert_record.
=over 4
=item insert_record
$record_obj->insert_record() : $flag
Attempt to insert the record into the database. Calls SUPER method, so implemented using MIXIN.
Clears the cache.
=back
=cut
# $record->insert_record()
sub insert_record {
my $self = shift;
$self->cache_clear();
$self->NEXT('insert_record', @_ );
}
########################################################################
=head2 Update to Change Records
After retrieving a record with one of the fetch methods, you may save any changes by calling update_record.
=over 4
=item update_record
$record_obj->update_record() : $record_count
Attempts to update the record using its primary key as a unique identifier.
Calls SUPER method, so implemented using MIXIN.
Clears the cache.
=back
=cut
# $record->update_record()
sub update_record {
my $self = shift;
$self->cache_clear();
$self->NEXT('update_record', @_ );
}
########################################################################
=head2 Delete to Remove Records
=over 4
=item delete_record()
$record_obj->delete_record() : $record_count
Delete this existing record based on its primary key.
Calls SUPER method, so implemented using MIXIN.
Clears the cache.
=back
=cut
# $record->delete_record()
sub delete_record {
my $self = shift;
$self->cache_clear();
$self->NEXT('delete_record', @_ );
}
########################################################################
########################################################################
=head1 SEE ALSO
For more about the Record classes, see L<DBIx::SQLEngine::Record::Class>.
See L<DBIx::SQLEngine> for the overall interface and developer documentation.
See L<DBIx::SQLEngine::Docs::ReadMe> for general information about
this distribution, including installation and license information.
=cut
########################################################################
1;
__END__
### DBO::Row::CachedRow
### Change History
# 2000-12-29 Added table_or_die() for better debugging output.
# 2000-05-24 Adjusted fall-back behavior in fetch_sql.
# 2000-04-12 Check whether being called on instance or class before blessing.
# 2000-04-11 Fixed really anoying fetch_id problem.
# 2000-04-05 Completed expiration and pruning methods.
# 2000-04-04 Check for empty-string criteria, ordering in cache_key_for_fetch
# 2000-03-29 Fixed cache expiration for multi-row fetch.
# 2000-03-06 Touchups.
# 2000-01-13 Overhauled. -Simon
########################################################################
########################################################################
# $rows = RowClass->fetch( $criteria, $order )
sub fetch {
my $self = shift;
return $self->query_cache->cache_get_set(
$self->cache_key_for_fetch( @_ ),
\&___cache_fetch, $self, @_
);
}
# $rows = RowClass->fetch_sql( $sql )
sub fetch_sql {
my $self = shift;
return $self->query_cache->cache_get_set(
join('__', @_),
\&___cache_fetch_sql, $self, @_
);
}
# $row = RowClass->fetch_id( $id )
sub fetch_id {
my $self = shift;
return $self->row_cache->cache_get_set(
join('__', @_),
\&___cache_fetch_id, $self, @_
);
}
########################################################################
sub insert_row {
my $row = shift;
$row->query_cache->clear_all() if ( $row->query_cache );
my $id_col = $row->table_or_die()->id_column();
my $row_cache = $row->row_cache;
if ( $id_col and $row_cache ) {
$row_cache->replace( $row->{$id_col}, $row );
}
return $row->NEXT('insert_row', @_);
}
sub update_row {
my $row = shift;
$row->query_cache->clear_all() if ( $row->query_cache );
return $row->NEXT('update_row', @_);
}
sub delete_row {
my $row = shift;
my $id_col = $row->table_or_die()->id_column();
my $row_cache = $row->row_cache;
if ( $id_col and $row_cache ) {
$row_cache->clear( $row->{$id_col} );
}
$row->query_cache->clear_all() if ( $row->query_cache );
return $row->NEXT('delete_row, @_);
}
1;
( run in 1.515 second using v1.01-cache-2.11-cpan-364913b4093 )