You are viewing a plain text version of this content. The canonical link for it is here.
Posted to taglibs-dev@jakarta.apache.org by bu...@apache.org on 2002/10/23 10:52:36 UTC

DO NOT REPLY [Bug 13873] New: - CacheEntry does not compute the proper size in bytes

DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG 
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://nagoya.apache.org/bugzilla/show_bug.cgi?id=13873>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND 
INSERTED IN THE BUG DATABASE.

http://nagoya.apache.org/bugzilla/show_bug.cgi?id=13873

CacheEntry does not compute the proper size in bytes

           Summary: CacheEntry does not compute the proper size in bytes
           Product: Taglibs
           Version: 1.0
          Platform: PC
        OS/Version: Other
            Status: NEW
          Severity: Normal
          Priority: Other
         Component: Cache  Taglib
        AssignedTo: taglibs-dev@jakarta.apache.org
        ReportedBy: chevalier@mkms.xerox.com


LRUCache.CacheEntry uses String.length() to compute the size of a string in 
bytes. The specification states that String.length() return the number of 16-
bit Unicode characters in the string. Unicode characters are usually 
represented using two bytes. Hence the real size is actually twice as big as 
the store one.

Another minor issue is that size was only registered when lifetime was superior 
to zero.

Below is a modified version of the constructor:
   public CacheEntry(String value) {
      this.value = value;
      if (lifetime > 0) {
        this.expiration = (new Date()).getTime() + lifetime;
      }

      // Pitch's fix: String.length() return the number of 16-bit Unicode 
      // characters in the string. Unicode characters are usually represented 
      // using two bytes. For Chinese characters or new Unicode schema, we
      // would be closer to reality by calling: String.getBytes().length
      this.size = 2 * value.length();
    }

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>