mIRC Home    About    Download    Register    News    Help

Print Thread
$finddir/$findfile - cached list. #141851 13/02/06 03:27 PM
Joined: Sep 2005
Posts: 2,878
H
hixxy Offline OP
Hoopy frood
OP Offline
Hoopy frood
H
Joined: Sep 2005
Posts: 2,878
I think it would be really nice if there was a cached list of results for the last $findfile call.

$findfile($mircdir,*.txt,0)
$findfilecache(1) -> 1.txt
$findfilecache(2) -> 2.txt
$findfilecache(3) -> 3.txt
$findfile($mircdir,*.mrc,0)
$findfilecache(1) -> 1.mrc
$findfilecache(2) -> 2.mrc
$findfilecache(3) -> 3.mrc
Etc..

$finddir would do the same.

Re: $finddir/$findfile - cached list. #141852 13/02/06 04:03 PM
Joined: Jan 2003
Posts: 2,523
Q
qwerty Offline
Hoopy frood
Offline
Hoopy frood
Q
Joined: Jan 2003
Posts: 2,523
If something like this was implemented, the cached data should be cleared as soon as the routine (alias or event) that called $findfile was finished, otherwise the cache could end up with invalid data (eg if a file is deleted in the meantime).

With this in mind, I can't see much use for it, as found filenames can already be referenced multiple times: either by $1- inside the alias in $findfile(dir,mask,0,alias $1-) or by $line(@win,N) after a $findfile(dir,mask,0,@win). The only case where this could be useful is if you call $findfile(dir,mask,0) (without a 4th parameter) to get the number of all matching files and later (in the same routine) you want to reference a single file (or certain files) by index, for example just get the 3rd and the 5th filename. This is a rather odd scenario though, I have never needed such a thing nor can I think of why anyone would. Can you give an example of a real-world use of such a feature?

On a sidenote, you probably know this already, but caching is already done by the system at the appropriate level, which is why subsequent calls of the same $findfile() are much faster.


/.timerQ 1 0 echo /.timerQ 1 0 $timer(Q).com
Re: $finddir/$findfile - cached list. #141853 13/02/06 04:09 PM
Joined: Sep 2005
Posts: 2,878
H
hixxy Offline OP
Hoopy frood
OP Offline
Hoopy frood
H
Joined: Sep 2005
Posts: 2,878
Really it'd just be for consistency with most other code (being able to use a while loop to loop through found files without a ridiculous speed decrease.)

Code:
alias listfiles {
  var %count = $findfile($mircdir,*.mrc,0), %i = 1
  while ($findfilecache(%i)) {
    echo -a $v1
    inc %i
  }
  echo -a * %count files found.
}


Most things in mIRC use loops; $hget, $timer, $read, $window, etc. Only a few rare cases use callbacks.

Re: $finddir/$findfile - cached list. #141854 13/02/06 04:19 PM
Joined: Apr 2004
Posts: 841
Sat Offline
Hoopy frood
Offline
Hoopy frood
Joined: Apr 2004
Posts: 841
Quote:
Most things in mIRC use loops; $hget, $timer, $read, $window, etc. Only a few rare cases use callbacks.

But none of those use a cache, even though that would be very desirable for e.g. $comval and $hget/$hfind. Unlike those, $findfile already gives you the opportunity to do the caching yourself, if you want to - if you don't, then mIRC would only eat up lots of memory by caching results you'll never use again.. So if this were to be added, it should at least be optional IMO.


Saturn, QuakeNet staff
Re: $finddir/$findfile - cached list. #141855 13/02/06 04:42 PM
Joined: Jan 2003
Posts: 2,523
Q
qwerty Offline
Hoopy frood
Offline
Hoopy frood
Q
Joined: Jan 2003
Posts: 2,523
For completeness' sake, I wouldn't mind having this too. Now that I think of it, this way you wouldn't have to pass parameters from the calling routine to the $findfile() alias or set up global vars etc either. I just thought you had something in mind that couldn't be done efficiently with the traditional methods (I tend to think economically regarding feature suggestions, seeing as there are too many of them for one programmer wink)

Edit: Sat's got a point too, the extra memory might matter when dealing with thousands of results

Last edited by qwerty; 13/02/06 04:50 PM.

/.timerQ 1 0 echo /.timerQ 1 0 $timer(Q).com
Re: $finddir/$findfile - cached list. #141856 14/02/06 01:24 AM
Joined: Sep 2005
Posts: 2,878
H
hixxy Offline OP
Hoopy frood
OP Offline
Hoopy frood
H
Joined: Sep 2005
Posts: 2,878
It could be optional with a property; $findfile().cache - make the cache (doesn't make it by default) / or $findfile().nocache - don't make the cache (makes it by default.)

As for the cache being cleared after the current routine ends (re: qwerty) I think that kinda defeats the point of having it (ie not having to use the same subsequent $findfile calls.) I think it should just be reset with each $findfile call and maybe there could be a command added to clear it.

Re: $finddir/$findfile - cached list. #141857 14/02/06 01:38 AM
Joined: Jan 2003
Posts: 2,523
Q
qwerty Offline
Hoopy frood
Offline
Hoopy frood
Q
Joined: Jan 2003
Posts: 2,523
There's already a $findfile() property, .shortfn. This and .cache aren't mutually exclusive so this can't work.


/.timerQ 1 0 echo /.timerQ 1 0 $timer(Q).com
Re: $finddir/$findfile - cached list. #141858 14/02/06 01:47 AM
Joined: Sep 2005
Posts: 2,878
H
hixxy Offline OP
Hoopy frood
OP Offline
Hoopy frood
H
Joined: Sep 2005
Posts: 2,878
Good point. Maybe an optional $true/$false parameter then ($false if not supplied.)