## org.w3c.www.protocol.http.cache
Class CacheGeneration

    java.lang.Object
      |
      +--org.w3c.www.protocol.http.cache.CacheGeneration

public class CacheGeneration
extends java.lang.Object
implements LRUAble

Field Summary
`protected java.io.File` `generationFile`
`protected LRUAble` `next` LRU management - next entry.
`protected LRUAble` `prev` LRU management - previous entry.

Constructor Summary
`CacheGeneration(CacheStore store, long maxsize)`

Method Summary
`boolean` `addResource(CachedResource cr, long size, long oldsize)` Adds this resource, if possible
`void` `clean()` Clean this generation.
`long` `collectSpace(long size, boolean check)` will garbage collect up to "size" bytes in this generation.
`boolean` `containsResource(java.lang.String url)` Check if a resource has been cached in this generation
`protected void` `copyInto(CacheGeneration gen)` copy the content of the generation here
`protected void` `deleteGenerationFile()` delete the serialized resource file from the disk
`long` `deleteStored(CachedResource cr)` Deletes a resource from the "to be deleted" vector it updates also the number of bye stored in this generation
`protected long` `emptyGeneration()` empty this generation
`long` `getByteLimit()` Get the bytecount limit for this generation
`long` `getCachedByteCount()` Give the acual occupation level of this generation
`java.util.Enumeration` `getCachedResources()` Get the CachedResource of this generation (except the "to be deleted" resources)
`int` `getCRCount()` Get the current number of resource loaded.
`java.util.Enumeration` `getDeletedResources()` get the deleted but still stored resource
`java.util.Enumeration` `getFiles()` Get all the files handled by this generation
`float` `getFillRatio()` Give the fill ratio for the cached resources
`java.io.File` `getGenerationFile()` get the generation file
`int` `getId()` Get the ID of this generation
`LRUAble` `getNext()` LRU management - Get next node.
`LRUAble` `getPrev()` LRU management - Get previous node.
`long` `getStoredByteCount()` Give the acual storeage occupation level of this generation
`boolean` `isLoaded()` Is the generation loaded?
`boolean` `isSaved()` Is the generation saved?
`protected void` `loadCachedResource(CachedResource cr)` Load a CachedResource in this generation.
`CachedResource` `lookupResource(java.lang.String url)` Get the CachedResource relative to the given URL.
`long` `removeResource(CachedResource cr)` Remove the resource from the generation (but don't delete it).
`long` `removeResource(java.lang.String url)` Remove the resource from the generation (but don't delete it).
`void` `setByteLimit(long newlimit)` Set the new bytecount limit, not that it may perform a cleanup if necessary.
`protected void` `setDescription(LookupTable[] tables)` Set this Generation as a description (update the saved and loaded status)
`void` `setGenerationFile(java.io.File generationFile)` set the file where the generation is stored
`void` `setId(int id)` Set the ID of this generation Useful to reuse generation
`protected void` `setLoaded(boolean loaded)` Set the generation as loaded or unloaded
`void` `setNext(LRUAble next)` LRU management - Set next node.
`void` `setPrev(LRUAble prev)` LRU management - Set previous node.
`protected void` `setSaved(boolean saved)` Set the generation as saved or not.
`void` `unload()` Unload the generation, transform CachedResources to descriptions.

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Field Detail

### generationFile

    protected java.io.File generationFile

### prev

    protected LRUAble prev

  LRU management - previous entry.

### next

    protected LRUAble next

  LRU management - next entry.

Constructor Detail

### CacheGeneration

    public CacheGeneration(CacheStore store,
                           long maxsize)

Method Detail

### setGenerationFile

    public void setGenerationFile(java.io.File generationFile)

  set the file where the generation is stored
  Parameters:
    `generationFile` - the file

### getGenerationFile

    public java.io.File getGenerationFile()

  get the generation file
  Returns:
    a File

### isLoaded

    public boolean isLoaded()

  Is the generation loaded?
  Returns:
    a boolean

### setLoaded

    protected void setLoaded(boolean loaded)

  Set the generation as loaded or unloaded
  Parameters:
    `loaded` - the new loaded flag

### isSaved

    public boolean isSaved()

  Is the generation saved?
  Returns:
    a boolean

### setSaved

    protected void setSaved(boolean saved)

  Set the generation as saved or not.
  Parameters:
    `saved` - a boolean

### getNext

    public LRUAble getNext()

  LRU management - Get next node.
  Specified by:
    getNext in interface LRUAble
  Returns:
    A CacheGeneration instance.

### getPrev

    public LRUAble getPrev()

  LRU management - Get previous node.
  Specified by:
    getPrev in interface LRUAble
  Returns:
    A CacheGeneration instance.

### setNext

    public void setNext(LRUAble next)

  LRU management - Set next node.
  Specified by:
    setNext in interface LRUAble

### setPrev

    public void setPrev(LRUAble prev)

  LRU management - Set previous node.
  Specified by:
    setPrev in interface LRUAble

### getId

    public int getId()

  Get the ID of this generation
  Returns:
    an int, the generation number

### setId

    public void setId(int id)

  Set the ID of this generation Useful to reuse generation
  Parameters:
    `an` - integer, the new generation number

### getCachedByteCount

    public long getCachedByteCount()

  Give the acual occupation level of this generation
  Returns:
    a long, the number of bytes of this generation

### getFillRatio

    public float getFillRatio()

  Give the fill ratio for the cached resources
  Returns:
    a float between 0 and 1

### getStoredByteCount

    public long getStoredByteCount()

  Give the acual storeage occupation level of this generation
  Returns:
    a long, the number of bytes of this generation

### getByteLimit

    public long getByteLimit()

  Get the bytecount limit for this generation
  Returns:
    a long, the maximum number of bytes

### setByteLimit

    public void setByteLimit(long newlimit)

  Set the new bytecount limit, not that it may perform a cleanup if necessary.
  Parameters:
    `long,` - the new maximum number of bytes

### deleteStored

    public long deleteStored(CachedResource cr)

  Deletes a resource from the "to be deleted" vector it updates also the number of bye stored in this generation
  Returns:
    the number of bytes saved.

### containsResource

    public boolean containsResource(java.lang.String url)

  Check if a resource has been cached in this generation
  Parameters:
    `url` - the resource url
  Returns:
    a boolean

### getFiles

    public java.util.Enumeration getFiles()

  Get all the files handled by this generation
  Returns:
    an enumeration of File

### lookupResource

    public CachedResource lookupResource(java.lang.String url)

  Get the CachedResource relative to the given URL.
  Parameters:
    `url` - the URL of the CachedResource to find
  Returns:
    a CachedResource or null.

### addResource

    public boolean addResource(CachedResource cr,
                               long size,
                               long oldsize)

  Adds this resource, if possible
  Parameters:
    `cr,` - the candidate.
    `size,` - the size of the candidate.
  Returns:
    a boolean, true if this resource has been cached

### loadCachedResource

    protected void loadCachedResource(CachedResource cr)

  Load a CachedResource in this generation. (to be used only at generation loading). This method load only valid cachedresource. Check if the associated file exists and has the right size.
  Parameters:
    `CachedResource` - the CachedResource to load.

### removeResource

    public long removeResource(CachedResource cr)
                        throws NoSuchResourceException

  Remove the resource from the generation (but don't delete it).
  Parameters:
    `cr` - the CachedResource to remove.
  Returns:
    the number of byte saved
  Throws:
    NoSuchResourceException - if this resource was not in this generation

### removeResource

    public long removeResource(java.lang.String url)
                        throws NoSuchResourceException

  Remove the resource from the generation (but don't delete it).
  Parameters:
    `cr` - the CachedResource to remove.
  Returns:
    the number of byte saved
  Throws:
    NoSuchResourceException - if this resource was not in this generation

### collectSpace

    public long collectSpace(long size,
                             boolean check)

  will garbage collect up to "size" bytes in this generation. WARNING: this is not synchronized, use with caution!
  Parameters:
    `long` - the number of bytes to be collected
    `check,` - a boolean, used to validate or not the resource before deleting them (ie: delete only invalid resources)
  Returns:
    a long, the number of bytes saved from disk afterward using delete.

### emptyGeneration

    protected long emptyGeneration()

  empty this generation
  Returns:
    a long, the number of bytes saved

### getCachedResources

    public java.util.Enumeration getCachedResources()

  Get the CachedResource of this generation (except the "to be deleted" resources)
  Returns:
    an Enumeration of CachedResource

### getDeletedResources

    public java.util.Enumeration getDeletedResources()

  get the deleted but still stored resource

### setDescription

    protected void setDescription(LookupTable[] tables)

  Set this Generation as a description (update the saved and loaded status)
  Parameters:
    `tables` - the LookupTables containing attribute descriptions

### unload

    public void unload()

  Unload the generation, transform CachedResources to descriptions.

### deleteGenerationFile

    protected void deleteGenerationFile()

  delete the serialized resource file from the disk

### getCRCount

    public int getCRCount()

  Get the current number of resource loaded.
  Returns:
    an long

### clean

    public void clean()

  Clean this generation.

### copyInto

    protected void copyInto(CacheGeneration gen)

  copy the content of the generation here