Paste: cache-get* (old stack version)

Author: dharmatech
Mode: factor
Date: Tue, 14 Oct 2008 07:19:04
Plain Text |
: query->rr ( query -- rr ) [ name>> ] [ type>> ] [ class>> ] tri f f rr boa ;

: query+entry->rrs ( query entry -- rrs )
  swap                                  ! entry query
  query->rr                             ! entry rr
  over                                  ! entry rr entry
  time>> time->ttl >>ttl                ! entry rr
  swap                                  ! rr entry
  data>> [ >r dup clone r> >>rdata ] map
  nip ;

! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

: expired? ( entry -- ? ) time>> time->ttl 0 <= ;

: cache-get* ( query -- rrs/NX/f )
  dup table-get               ! query result
    {
      { [ dup f = ]      [ 2drop f ]          } ! not in the cache
      { [ dup expired? ] [ drop table-rem f ] } ! here but expired
      { [ dup nx?  ]     [ 2drop NX ]         } ! negative result cached
      { [ t ]            [ query+entry->rrs ] } ! good to go
    }
  cond ;

Annotation: no shuffling

Author: prunedtree
Mode: factor
Date: Tue, 14 Oct 2008 07:27:44
Plain Text |
:: (cache-get*) ( query table -- rrs/NX/f )
    {
      { [ dup f = ]      [ f ]          } ! not in the cache
      { [ dup expired? ] [ query table-rem f ] } ! here but expired
      { [ dup nx?  ]     [ NX ]         } ! negative result cached
      { [ t ]            [ table query+entry->rrs ] } ! good to go
    }
  cond ;

: cache-get* ( query -- rrs/NX/f )
  dup table-get (cache-get*)

Annotation: less shuffling

Author: prunedtree
Mode: factor
Date: Tue, 14 Oct 2008 07:41:07
Plain Text |
: query->rr ( query -- rr ) [ name>> ] [ type>> ] [ class>> ] tri f f rr boa ; ! this one looks good enough imho

: query+entry->rrs ( query entry -- rrs )
   [ query->rr ] dip
   dup time>> time->ttl >>ttl
   [ data>> ] dip
   [ clone swap >>rdata ] curry map

:: (cache-get*) ( query table -- rrs/NX/f )
    table
    {
      { [ f = ]      [ f ]          } ! not in the cache
      { [ expired? ] [ query table-rem f ] } ! here but expired
      { [ nx?  ]     [ NX ]         } ! negative result cached
      { [ t ]            [ query table query+entry->rrs ] } ! good to go
    }
  cond' ; ! hypothetical combinator ;) (dups before all predicates, eats it's argument)

: cache-get* ( query -- rrs/NX/f )
  dup table-get (cache-get*)

New Annotation

Summary:
Author:
Mode:
Body: