AmberDB
view release on metacpan or search on metacpan
lib/AmberDB/Base/Ramdisk.pm view on Meta::CPAN
sub _check_ramdisk_ttl {
my ( $self, $tableid, $file_path ) = @_;
return 1 unless -e $file_path;
my $table_info = $self->table_info($tableid);
my $use_ramdisk = $table_info ? ( $table_info->{use_ramdisk} // 0 ) : 0;
return 1 unless $use_ramdisk == 3;
my $ttl = $table_info ? ( $table_info->{ramdisk_ttl} // 300 ) : 300;
if ( defined $ttl && $ttl > 0 ) {
my $mtime = ( stat($file_path) )[9];
if ( defined $mtime && ( time() - $mtime ) > $ttl ) {
$self->table_close($file_path);
unlink $file_path;
return 0;
}
}
return 1;
}
my %RAMDISK_ENSURING;
lib/AmberDB/Base/Schema.pm view on Meta::CPAN
if ( $self->{_table}->{$table} && %{ $self->{_table}->{$table} } ) {
return { %{ $self->{_table}->{$table} } };
}
my ($dbase) = ( $table =~ /^([a-z0-9]+)_/i );
$dbase //= "";
my $ramdisk_schema = $self->path('schema_rdir');
my $target_path = $table_path;
if ( $ramdisk_schema && -e "$ramdisk_schema/$table.table" ) {
if ( -e $table_path && ( ( stat($table_path) )[9] > ( stat("$ramdisk_schema/$table.table") )[9] ) ) {
require File::Copy;
eval { File::Copy::copy( $table_path, "$ramdisk_schema/$table.table" ) };
}
$target_path = "$ramdisk_schema/$table.table";
}
if ( my $do_data = $self->do_schema($target_path) ) {
$self->normalize_blocks( $table, $do_data );
$self->{_table}->{$table} = $do_data;
lib/AmberDB/Tools/Update.pm view on Meta::CPAN
my $table_path = $adb->table_path($tableid);
my $ext = $adb->{db_ext} || "db";
my $file_path = "$table_path.$ext";
# Use exist_table to verify primary table existence
return { status => 'not_found', table => $tableid }
unless $adb->exist_table( $tableid );
# Format modification timestamp: YYYY-MMDD
my @mtime_parts = localtime( ( stat($file_path) )[9] || time() );
my $mtime_str = sprintf( "%04d-%02d%02d", $mtime_parts[5] + 1900, $mtime_parts[4] + 1, $mtime_parts[3] );
# 1. Once mevcut tablodaki kayitlari tara
my %format_counts;
my $total = 0;
my $already_current = 0;
my $legacy_count = 0;
my @decoded_records;
my $recovered_from_backup = 0;
xt/amberdb_ramdisk.t view on Meta::CPAN
ok( !-e $temp_db, 'Expired file was unlinked by _check_ramdisk_ttl' );
is( $adb->table_count('temp_cache'), 0, 'table_count returns 0 for expired table' );
# 8. Sliding Expiration
$adb->table_attr( 'sliding_cache', use_ramdisk => 3, ramdisk_ttl => 60 );
ok( $adb->insert_id( 'sliding_cache', 1, 'slide_data' ), 'sliding_cache record inserted' );
my $slide_db = File::Spec->catfile( $ramdisk_dir, 'table', 'sliding_cache.db' );
# Backdate mtime slightly (25 seconds ago, < 60s TTL)
utime( time() - 25, time() - 25, $slide_db );
my $mtime_old = ( stat($slide_db) )[9];
my @slide_rec = $adb->read_id( 'sliding_cache', 1 );
is( $slide_rec[1], 'slide_data', 'Unexpired record readable' );
my $mtime_new = ( stat($slide_db) )[9];
cmp_ok( $mtime_new, '>', $mtime_old, 'read_id refreshed mtime (sliding expiration)' );
};
subtest 'table_dir custom storage directory (Disk & RAM-Disk)' => sub {
my $tmp = File::Temp->newdir( CLEANUP => 1 );
my $tbl_mount = File::Temp->newdir( CLEANUP => 1 );
my $tbl_ram = File::Spec->catdir( $tbl_mount, 'amberdb_siparis' );
make_path($tbl_ram);
local $ENV{AMBERDB_TEST_RAMDISK} = 1;
( run in 2.252 seconds using v1.01-cache-2.11-cpan-cb04b646d8c )