Skip to content

Commit

Permalink
- fixed a bug in the caching logic where I was loading the content mo…
Browse files Browse the repository at this point in the history
…re than once per instance, when really I only need to do it once.
  • Loading branch information
mikepultz committed Jan 15, 2017
1 parent 690b365 commit c46c12d
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 2 deletions.
6 changes: 6 additions & 0 deletions Net/DNS2/Cache.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,12 @@ class Net_DNS2_Cache
*/
protected $cache_serializer;

/*
* an internal flag to make sure we don't load the cache content more
* than once per instance.
*/
protected $cache_opened = false;

/**
* returns true/false if the provided key is defined in the cache
*
Expand Down
9 changes: 7 additions & 2 deletions Net/DNS2/Cache/File.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,10 @@ public function open($cache_file, $size, $serializer)
//
// check that the file exists first
//
if ( (file_exists($this->cache_file) == true)
if ( ($this->cache_opened == false)
&& (file_exists($this->cache_file) == true)
&& (filesize($this->cache_file) > 0)
) {

//
// open the file for reading
//
Expand Down Expand Up @@ -135,6 +135,11 @@ public function open($cache_file, $size, $serializer)
// clean up the data
//
$this->clean();

//
// mark this so we don't read this contents more than once per instance.
//
$this->cache_opened = true;
}
}
}
Expand Down
13 changes: 13 additions & 0 deletions Net/DNS2/Cache/Shm.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,14 @@ public function open($cache_file, $size, $serializer)
$this->cache_file = $cache_file;
$this->cache_serializer = $serializer;

//
// if we've already loaded the cache data, then just return right away
//
if ($this->cache_opened == true)
{
return;
}

//
// make sure the file exists first
//
Expand Down Expand Up @@ -161,6 +169,11 @@ public function open($cache_file, $size, $serializer)
// call clean to clean up old entries
//
$this->clean();

//
// mark the cache as loaded, so we don't load it more than once
//
$this->cache_opened = true;
}
}
}
Expand Down
1 change: 1 addition & 0 deletions package.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
$pkg->setReleaseStability('stable');
$pkg->setAPIStability('stable');
$pkg->setNotes(
"- fixed a bug in the caching logic where I was loading the content more than once per instance, when really I only need to do it once.\n" .
"- changed the Net_DNS2::sock array to use the SOCK_DGRAM and SOCK_STREAM defines, rather than the strings 'tcp' or 'udp'.\n" .
"- fixed a bug in the Net_DNS2_Header and Net_DNS2_Question classes, where I was using the wrong bit-shift operators when parsing some of the values. This only became apparent when somebody was trying to use the CAA class (id 257); it was causing this to roll over to the next 8 bit value, and returning 1 (RR A) instead of the CAA class.\n" .
"- fixed a bug that occurs when a DNS lookup request times out, and then the same class is reused for a subsequent request. Because I'm caching the sockets, the timed out data could eventually come in, and end up being seen as the result for a subsequent lookup.\n" .
Expand Down

0 comments on commit c46c12d

Please sign in to comment.