1*0Sstevel@tonic-gate 2*0Sstevel@tonic-gatepackage Memoize::Expire; 3*0Sstevel@tonic-gate# require 5.00556; 4*0Sstevel@tonic-gateuse Carp; 5*0Sstevel@tonic-gate$DEBUG = 0; 6*0Sstevel@tonic-gate$VERSION = '1.00'; 7*0Sstevel@tonic-gate 8*0Sstevel@tonic-gate# This package will implement expiration by prepending a fixed-length header 9*0Sstevel@tonic-gate# to the font of the cached data. The format of the header will be: 10*0Sstevel@tonic-gate# (4-byte number of last-access-time) (For LRU when I implement it) 11*0Sstevel@tonic-gate# (4-byte expiration time: unsigned seconds-since-unix-epoch) 12*0Sstevel@tonic-gate# (2-byte number-of-uses-before-expire) 13*0Sstevel@tonic-gate 14*0Sstevel@tonic-gatesub _header_fmt () { "N N n" } 15*0Sstevel@tonic-gatesub _header_size () { length(_header_fmt) } 16*0Sstevel@tonic-gate 17*0Sstevel@tonic-gate# Usage: memoize func 18*0Sstevel@tonic-gate# TIE => [Memoize::Expire, LIFETIME => sec, NUM_USES => n, 19*0Sstevel@tonic-gate# TIE => [...] ] 20*0Sstevel@tonic-gate 21*0Sstevel@tonic-gateBEGIN { 22*0Sstevel@tonic-gate eval {require Time::HiRes}; 23*0Sstevel@tonic-gate unless ($@) { 24*0Sstevel@tonic-gate Time::HiRes->import('time'); 25*0Sstevel@tonic-gate } 26*0Sstevel@tonic-gate} 27*0Sstevel@tonic-gate 28*0Sstevel@tonic-gatesub TIEHASH { 29*0Sstevel@tonic-gate my ($package, %args) = @_; 30*0Sstevel@tonic-gate my %cache; 31*0Sstevel@tonic-gate if ($args{TIE}) { 32*0Sstevel@tonic-gate my ($module, @opts) = @{$args{TIE}}; 33*0Sstevel@tonic-gate my $modulefile = $module . '.pm'; 34*0Sstevel@tonic-gate $modulefile =~ s{::}{/}g; 35*0Sstevel@tonic-gate eval { require $modulefile }; 36*0Sstevel@tonic-gate if ($@) { 37*0Sstevel@tonic-gate croak "Memoize::Expire: Couldn't load hash tie module `$module': $@; aborting"; 38*0Sstevel@tonic-gate } 39*0Sstevel@tonic-gate my $rc = (tie %cache => $module, @opts); 40*0Sstevel@tonic-gate unless ($rc) { 41*0Sstevel@tonic-gate croak "Memoize::Expire: Couldn't tie hash to `$module': $@; aborting"; 42*0Sstevel@tonic-gate } 43*0Sstevel@tonic-gate } 44*0Sstevel@tonic-gate $args{LIFETIME} ||= 0; 45*0Sstevel@tonic-gate $args{NUM_USES} ||= 0; 46*0Sstevel@tonic-gate $args{C} = \%cache; 47*0Sstevel@tonic-gate bless \%args => $package; 48*0Sstevel@tonic-gate} 49*0Sstevel@tonic-gate 50*0Sstevel@tonic-gatesub STORE { 51*0Sstevel@tonic-gate $DEBUG and print STDERR " >> Store $_[1] $_[2]\n"; 52*0Sstevel@tonic-gate my ($self, $key, $value) = @_; 53*0Sstevel@tonic-gate my $expire_time = $self->{LIFETIME} > 0 ? $self->{LIFETIME} + time : 0; 54*0Sstevel@tonic-gate # The call that results in a value to store into the cache is the 55*0Sstevel@tonic-gate # first of the NUM_USES allowed calls. 56*0Sstevel@tonic-gate my $header = _make_header(time, $expire_time, $self->{NUM_USES}-1); 57*0Sstevel@tonic-gate $self->{C}{$key} = $header . $value; 58*0Sstevel@tonic-gate $value; 59*0Sstevel@tonic-gate} 60*0Sstevel@tonic-gate 61*0Sstevel@tonic-gatesub FETCH { 62*0Sstevel@tonic-gate $DEBUG and print STDERR " >> Fetch cached value for $_[1]\n"; 63*0Sstevel@tonic-gate my ($data, $last_access, $expire_time, $num_uses_left) = _get_item($_[0]{C}{$_[1]}); 64*0Sstevel@tonic-gate $DEBUG and print STDERR " >> (ttl: ", ($expire_time-time()), ", nuses: $num_uses_left)\n"; 65*0Sstevel@tonic-gate $num_uses_left--; 66*0Sstevel@tonic-gate $last_access = time; 67*0Sstevel@tonic-gate _set_header(@_, $data, $last_access, $expire_time, $num_uses_left); 68*0Sstevel@tonic-gate $data; 69*0Sstevel@tonic-gate} 70*0Sstevel@tonic-gate 71*0Sstevel@tonic-gatesub EXISTS { 72*0Sstevel@tonic-gate $DEBUG and print STDERR " >> Exists $_[1]\n"; 73*0Sstevel@tonic-gate unless (exists $_[0]{C}{$_[1]}) { 74*0Sstevel@tonic-gate $DEBUG and print STDERR " Not in underlying hash at all.\n"; 75*0Sstevel@tonic-gate return 0; 76*0Sstevel@tonic-gate } 77*0Sstevel@tonic-gate my $item = $_[0]{C}{$_[1]}; 78*0Sstevel@tonic-gate my ($last_access, $expire_time, $num_uses_left) = _get_header($item); 79*0Sstevel@tonic-gate my $ttl = $expire_time - time; 80*0Sstevel@tonic-gate if ($DEBUG) { 81*0Sstevel@tonic-gate $_[0]{LIFETIME} and print STDERR " Time to live for this item: $ttl\n"; 82*0Sstevel@tonic-gate $_[0]{NUM_USES} and print STDERR " Uses remaining: $num_uses_left\n"; 83*0Sstevel@tonic-gate } 84*0Sstevel@tonic-gate if ( (! $_[0]{LIFETIME} || $expire_time > time) 85*0Sstevel@tonic-gate && (! $_[0]{NUM_USES} || $num_uses_left > 0 )) { 86*0Sstevel@tonic-gate $DEBUG and print STDERR " (Still good)\n"; 87*0Sstevel@tonic-gate return 1; 88*0Sstevel@tonic-gate } else { 89*0Sstevel@tonic-gate $DEBUG and print STDERR " (Expired)\n"; 90*0Sstevel@tonic-gate return 0; 91*0Sstevel@tonic-gate } 92*0Sstevel@tonic-gate} 93*0Sstevel@tonic-gate 94*0Sstevel@tonic-gate# Arguments: last access time, expire time, number of uses remaining 95*0Sstevel@tonic-gatesub _make_header { 96*0Sstevel@tonic-gate pack "N N n", @_; 97*0Sstevel@tonic-gate} 98*0Sstevel@tonic-gate 99*0Sstevel@tonic-gatesub _strip_header { 100*0Sstevel@tonic-gate substr($_[0], 10); 101*0Sstevel@tonic-gate} 102*0Sstevel@tonic-gate 103*0Sstevel@tonic-gate# Arguments: last access time, expire time, number of uses remaining 104*0Sstevel@tonic-gatesub _set_header { 105*0Sstevel@tonic-gate my ($self, $key, $data, @header) = @_; 106*0Sstevel@tonic-gate $self->{C}{$key} = _make_header(@header) . $data; 107*0Sstevel@tonic-gate} 108*0Sstevel@tonic-gate 109*0Sstevel@tonic-gatesub _get_item { 110*0Sstevel@tonic-gate my $data = substr($_[0], 10); 111*0Sstevel@tonic-gate my @header = unpack "N N n", substr($_[0], 0, 10); 112*0Sstevel@tonic-gate# print STDERR " >> _get_item: $data => $data @header\n"; 113*0Sstevel@tonic-gate ($data, @header); 114*0Sstevel@tonic-gate} 115*0Sstevel@tonic-gate 116*0Sstevel@tonic-gate# Return last access time, expire time, number of uses remaining 117*0Sstevel@tonic-gatesub _get_header { 118*0Sstevel@tonic-gate unpack "N N n", substr($_[0], 0, 10); 119*0Sstevel@tonic-gate} 120*0Sstevel@tonic-gate 121*0Sstevel@tonic-gate1; 122*0Sstevel@tonic-gate 123*0Sstevel@tonic-gate=head1 NAME 124*0Sstevel@tonic-gate 125*0Sstevel@tonic-gateMemoize::Expire - Plug-in module for automatic expiration of memoized values 126*0Sstevel@tonic-gate 127*0Sstevel@tonic-gate=head1 SYNOPSIS 128*0Sstevel@tonic-gate 129*0Sstevel@tonic-gate use Memoize; 130*0Sstevel@tonic-gate use Memoize::Expire; 131*0Sstevel@tonic-gate tie my %cache => 'Memoize::Expire', 132*0Sstevel@tonic-gate LIFETIME => $lifetime, # In seconds 133*0Sstevel@tonic-gate NUM_USES => $n_uses; 134*0Sstevel@tonic-gate 135*0Sstevel@tonic-gate memoize 'function', SCALAR_CACHE => [HASH => \%cache ]; 136*0Sstevel@tonic-gate 137*0Sstevel@tonic-gate=head1 DESCRIPTION 138*0Sstevel@tonic-gate 139*0Sstevel@tonic-gateMemoize::Expire is a plug-in module for Memoize. It allows the cached 140*0Sstevel@tonic-gatevalues for memoized functions to expire automatically. This manual 141*0Sstevel@tonic-gateassumes you are already familiar with the Memoize module. If not, you 142*0Sstevel@tonic-gateshould study that manual carefully first, paying particular attention 143*0Sstevel@tonic-gateto the HASH feature. 144*0Sstevel@tonic-gate 145*0Sstevel@tonic-gateMemoize::Expire is a layer of software that you can insert in between 146*0Sstevel@tonic-gateMemoize itself and whatever underlying package implements the cache. 147*0Sstevel@tonic-gateThe layer presents a hash variable whose values expire whenever they 148*0Sstevel@tonic-gateget too old, have been used too often, or both. You tell C<Memoize> to 149*0Sstevel@tonic-gateuse this forgetful hash as its cache instead of the default, which is 150*0Sstevel@tonic-gatean ordinary hash. 151*0Sstevel@tonic-gate 152*0Sstevel@tonic-gateTo specify a real-time timeout, supply the C<LIFETIME> option with a 153*0Sstevel@tonic-gatenumeric value. Cached data will expire after this many seconds, and 154*0Sstevel@tonic-gatewill be looked up afresh when it expires. When a data item is looked 155*0Sstevel@tonic-gateup afresh, its lifetime is reset. 156*0Sstevel@tonic-gate 157*0Sstevel@tonic-gateIf you specify C<NUM_USES> with an argument of I<n>, then each cached 158*0Sstevel@tonic-gatedata item will be discarded and looked up afresh after the I<n>th time 159*0Sstevel@tonic-gateyou access it. When a data item is looked up afresh, its number of 160*0Sstevel@tonic-gateuses is reset. 161*0Sstevel@tonic-gate 162*0Sstevel@tonic-gateIf you specify both arguments, data will be discarded from the cache 163*0Sstevel@tonic-gatewhen either expiration condition holds. 164*0Sstevel@tonic-gate 165*0Sstevel@tonic-gateMemoize::Expire uses a real hash internally to store the cached data. 166*0Sstevel@tonic-gateYou can use the C<HASH> option to Memoize::Expire to supply a tied 167*0Sstevel@tonic-gatehash in place of the ordinary hash that Memoize::Expire will normally 168*0Sstevel@tonic-gateuse. You can use this feature to add Memoize::Expire as a layer in 169*0Sstevel@tonic-gatebetween a persistent disk hash and Memoize. If you do this, you get a 170*0Sstevel@tonic-gatepersistent disk cache whose entries expire automatically. For 171*0Sstevel@tonic-gateexample: 172*0Sstevel@tonic-gate 173*0Sstevel@tonic-gate # Memoize 174*0Sstevel@tonic-gate # | 175*0Sstevel@tonic-gate # Memoize::Expire enforces data expiration policy 176*0Sstevel@tonic-gate # | 177*0Sstevel@tonic-gate # DB_File implements persistence of data in a disk file 178*0Sstevel@tonic-gate # | 179*0Sstevel@tonic-gate # Disk file 180*0Sstevel@tonic-gate 181*0Sstevel@tonic-gate use Memoize; 182*0Sstevel@tonic-gate use Memoize::Expire; 183*0Sstevel@tonic-gate use DB_File; 184*0Sstevel@tonic-gate 185*0Sstevel@tonic-gate # Set up persistence 186*0Sstevel@tonic-gate tie my %disk_cache => 'DB_File', $filename, O_CREAT|O_RDWR, 0666]; 187*0Sstevel@tonic-gate 188*0Sstevel@tonic-gate # Set up expiration policy, supplying persistent hash as a target 189*0Sstevel@tonic-gate tie my %cache => 'Memoize::Expire', 190*0Sstevel@tonic-gate LIFETIME => $lifetime, # In seconds 191*0Sstevel@tonic-gate NUM_USES => $n_uses, 192*0Sstevel@tonic-gate HASH => \%disk_cache; 193*0Sstevel@tonic-gate 194*0Sstevel@tonic-gate # Set up memoization, supplying expiring persistent hash for cache 195*0Sstevel@tonic-gate memoize 'function', SCALAR_CACHE => [ HASH => \%cache ]; 196*0Sstevel@tonic-gate 197*0Sstevel@tonic-gate=head1 INTERFACE 198*0Sstevel@tonic-gate 199*0Sstevel@tonic-gateThere is nothing special about Memoize::Expire. It is just an 200*0Sstevel@tonic-gateexample. If you don't like the policy that it implements, you are 201*0Sstevel@tonic-gatefree to write your own expiration policy module that implements 202*0Sstevel@tonic-gatewhatever policy you desire. Here is how to do that. Let us suppose 203*0Sstevel@tonic-gatethat your module will be named MyExpirePolicy. 204*0Sstevel@tonic-gate 205*0Sstevel@tonic-gateShort summary: You need to create a package that defines four methods: 206*0Sstevel@tonic-gate 207*0Sstevel@tonic-gate=over 4 208*0Sstevel@tonic-gate 209*0Sstevel@tonic-gate=item 210*0Sstevel@tonic-gateTIEHASH 211*0Sstevel@tonic-gate 212*0Sstevel@tonic-gateConstruct and return cache object. 213*0Sstevel@tonic-gate 214*0Sstevel@tonic-gate=item 215*0Sstevel@tonic-gateEXISTS 216*0Sstevel@tonic-gate 217*0Sstevel@tonic-gateGiven a function argument, is the corresponding function value in the 218*0Sstevel@tonic-gatecache, and if so, is it fresh enough to use? 219*0Sstevel@tonic-gate 220*0Sstevel@tonic-gate=item 221*0Sstevel@tonic-gateFETCH 222*0Sstevel@tonic-gate 223*0Sstevel@tonic-gateGiven a function argument, look up the corresponding function value in 224*0Sstevel@tonic-gatethe cache and return it. 225*0Sstevel@tonic-gate 226*0Sstevel@tonic-gate=item 227*0Sstevel@tonic-gateSTORE 228*0Sstevel@tonic-gate 229*0Sstevel@tonic-gateGiven a function argument and the corresponding function value, store 230*0Sstevel@tonic-gatethem into the cache. 231*0Sstevel@tonic-gate 232*0Sstevel@tonic-gate=item 233*0Sstevel@tonic-gateCLEAR 234*0Sstevel@tonic-gate 235*0Sstevel@tonic-gate(Optional.) Flush the cache completely. 236*0Sstevel@tonic-gate 237*0Sstevel@tonic-gate=back 238*0Sstevel@tonic-gate 239*0Sstevel@tonic-gateThe user who wants the memoization cache to be expired according to 240*0Sstevel@tonic-gateyour policy will say so by writing 241*0Sstevel@tonic-gate 242*0Sstevel@tonic-gate tie my %cache => 'MyExpirePolicy', args...; 243*0Sstevel@tonic-gate memoize 'function', SCALAR_CACHE => [HASH => \%cache]; 244*0Sstevel@tonic-gate 245*0Sstevel@tonic-gateThis will invoke C<< MyExpirePolicy->TIEHASH(args) >>. 246*0Sstevel@tonic-gateMyExpirePolicy::TIEHASH should do whatever is appropriate to set up 247*0Sstevel@tonic-gatethe cache, and it should return the cache object to the caller. 248*0Sstevel@tonic-gate 249*0Sstevel@tonic-gateFor example, MyExpirePolicy::TIEHASH might create an object that 250*0Sstevel@tonic-gatecontains a regular Perl hash (which it will to store the cached 251*0Sstevel@tonic-gatevalues) and some extra information about the arguments and how old the 252*0Sstevel@tonic-gatedata is and things like that. Let us call this object `C'. 253*0Sstevel@tonic-gate 254*0Sstevel@tonic-gateWhen Memoize needs to check to see if an entry is in the cache 255*0Sstevel@tonic-gatealready, it will invoke C<< C->EXISTS(key) >>. C<key> is the normalized 256*0Sstevel@tonic-gatefunction argument. MyExpirePolicy::EXISTS should return 0 if the key 257*0Sstevel@tonic-gateis not in the cache, or if it has expired, and 1 if an unexpired value 258*0Sstevel@tonic-gateis in the cache. It should I<not> return C<undef>, because there is a 259*0Sstevel@tonic-gatebug in some versions of Perl that will cause a spurious FETCH if the 260*0Sstevel@tonic-gateEXISTS method returns C<undef>. 261*0Sstevel@tonic-gate 262*0Sstevel@tonic-gateIf your EXISTS function returns true, Memoize will try to fetch the 263*0Sstevel@tonic-gatecached value by invoking C<< C->FETCH(key) >>. MyExpirePolicy::FETCH should 264*0Sstevel@tonic-gatereturn the cached value. Otherwise, Memoize will call the memoized 265*0Sstevel@tonic-gatefunction to compute the appropriate value, and will store it into the 266*0Sstevel@tonic-gatecache by calling C<< C->STORE(key, value) >>. 267*0Sstevel@tonic-gate 268*0Sstevel@tonic-gateHere is a very brief example of a policy module that expires each 269*0Sstevel@tonic-gatecache item after ten seconds. 270*0Sstevel@tonic-gate 271*0Sstevel@tonic-gate package Memoize::TenSecondExpire; 272*0Sstevel@tonic-gate 273*0Sstevel@tonic-gate sub TIEHASH { 274*0Sstevel@tonic-gate my ($package, %args) = @_; 275*0Sstevel@tonic-gate my $cache = $args{HASH} || {}; 276*0Sstevel@tonic-gate bless $cache => $package; 277*0Sstevel@tonic-gate } 278*0Sstevel@tonic-gate 279*0Sstevel@tonic-gate sub EXISTS { 280*0Sstevel@tonic-gate my ($cache, $key) = @_; 281*0Sstevel@tonic-gate if (exists $cache->{$key} && 282*0Sstevel@tonic-gate $cache->{$key}{EXPIRE_TIME} > time) { 283*0Sstevel@tonic-gate return 1 284*0Sstevel@tonic-gate } else { 285*0Sstevel@tonic-gate return 0; # Do NOT return `undef' here. 286*0Sstevel@tonic-gate } 287*0Sstevel@tonic-gate } 288*0Sstevel@tonic-gate 289*0Sstevel@tonic-gate sub FETCH { 290*0Sstevel@tonic-gate my ($cache, $key) = @_; 291*0Sstevel@tonic-gate return $cache->{$key}{VALUE}; 292*0Sstevel@tonic-gate } 293*0Sstevel@tonic-gate 294*0Sstevel@tonic-gate sub STORE { 295*0Sstevel@tonic-gate my ($cache, $key, $newvalue) = @_; 296*0Sstevel@tonic-gate $cache->{$key}{VALUE} = $newvalue; 297*0Sstevel@tonic-gate $cache->{$key}{EXPIRE_TIME} = time + 10; 298*0Sstevel@tonic-gate } 299*0Sstevel@tonic-gate 300*0Sstevel@tonic-gateTo use this expiration policy, the user would say 301*0Sstevel@tonic-gate 302*0Sstevel@tonic-gate use Memoize; 303*0Sstevel@tonic-gate tie my %cache10sec => 'Memoize::TenSecondExpire'; 304*0Sstevel@tonic-gate memoize 'function', SCALAR_CACHE => [HASH => \%cache10sec]; 305*0Sstevel@tonic-gate 306*0Sstevel@tonic-gateMemoize would then call C<function> whenever a cached value was 307*0Sstevel@tonic-gateentirely absent or was older than ten seconds. 308*0Sstevel@tonic-gate 309*0Sstevel@tonic-gateYou should always support a C<HASH> argument to C<TIEHASH> that ties 310*0Sstevel@tonic-gatethe underlying cache so that the user can specify that the cache is 311*0Sstevel@tonic-gatealso persistent or that it has some other interesting semantics. The 312*0Sstevel@tonic-gateexample above demonstrates how to do this, as does C<Memoize::Expire>. 313*0Sstevel@tonic-gate 314*0Sstevel@tonic-gate=head1 ALTERNATIVES 315*0Sstevel@tonic-gate 316*0Sstevel@tonic-gateBrent Powers has a C<Memoize::ExpireLRU> module that was designed to 317*0Sstevel@tonic-gatework with Memoize and provides expiration of least-recently-used data. 318*0Sstevel@tonic-gateThe cache is held at a fixed number of entries, and when new data 319*0Sstevel@tonic-gatecomes in, the least-recently used data is expired. See 320*0Sstevel@tonic-gateL<http://search.cpan.org/search?mode=module&query=ExpireLRU>. 321*0Sstevel@tonic-gate 322*0Sstevel@tonic-gateJoshua Chamas's Tie::Cache module may be useful as an expiration 323*0Sstevel@tonic-gatemanager. (If you try this, let me know how it works out.) 324*0Sstevel@tonic-gate 325*0Sstevel@tonic-gateIf you develop any useful expiration managers that you think should be 326*0Sstevel@tonic-gatedistributed with Memoize, please let me know. 327*0Sstevel@tonic-gate 328*0Sstevel@tonic-gate=head1 CAVEATS 329*0Sstevel@tonic-gate 330*0Sstevel@tonic-gateThis module is experimental, and may contain bugs. Please report bugs 331*0Sstevel@tonic-gateto the address below. 332*0Sstevel@tonic-gate 333*0Sstevel@tonic-gateNumber-of-uses is stored as a 16-bit unsigned integer, so can't exceed 334*0Sstevel@tonic-gate65535. 335*0Sstevel@tonic-gate 336*0Sstevel@tonic-gateBecause of clock granularity, expiration times may occur up to one 337*0Sstevel@tonic-gatesecond sooner than you expect. For example, suppose you store a value 338*0Sstevel@tonic-gatewith a lifetime of ten seconds, and you store it at 12:00:00.998 on a 339*0Sstevel@tonic-gatecertain day. Memoize will look at the clock and see 12:00:00. Then 340*0Sstevel@tonic-gate9.01 seconds later, at 12:00:10.008 you try to read it back. Memoize 341*0Sstevel@tonic-gatewill look at the clock and see 12:00:10 and conclude that the value 342*0Sstevel@tonic-gatehas expired. This will probably not occur if you have 343*0Sstevel@tonic-gateC<Time::HiRes> installed. 344*0Sstevel@tonic-gate 345*0Sstevel@tonic-gate=head1 AUTHOR 346*0Sstevel@tonic-gate 347*0Sstevel@tonic-gateMark-Jason Dominus (mjd-perl-memoize+@plover.com) 348*0Sstevel@tonic-gate 349*0Sstevel@tonic-gateMike Cariaso provided valuable insight into the best way to solve this 350*0Sstevel@tonic-gateproblem. 351*0Sstevel@tonic-gate 352*0Sstevel@tonic-gate=head1 SEE ALSO 353*0Sstevel@tonic-gate 354*0Sstevel@tonic-gateperl(1) 355*0Sstevel@tonic-gate 356*0Sstevel@tonic-gateThe Memoize man page. 357*0Sstevel@tonic-gate 358*0Sstevel@tonic-gatehttp://www.plover.com/~mjd/perl/Memoize/ (for news and updates) 359*0Sstevel@tonic-gate 360*0Sstevel@tonic-gateI maintain a mailing list on which I occasionally announce new 361*0Sstevel@tonic-gateversions of Memoize. The list is for announcements only, not 362*0Sstevel@tonic-gatediscussion. To join, send an empty message to 363*0Sstevel@tonic-gatemjd-perl-memoize-request@Plover.com. 364*0Sstevel@tonic-gate 365*0Sstevel@tonic-gate=cut 366