Servertec   FileCache
Content
Introduction
Release Notes
Features
FAQs
Requirements
Installation
Add-ons
How To
Change Log
Future Plans
Knowledge Base
Documentation
Conventions
Users
Reference
iServer API
AccessLogEntry
Codecs
Connection
ConnectionPool...
DString
ErrorLogEntry
EventLogEntry
FileCache
FileUpload
IOHandler
IOManager
iws
Logger
MultiPartForm
QuickSort
QuickSortString...
Realm
RealmAdmin...
RealmManager
ServletContextImpl
ServletContext...
ServletImpl
ServletManager
Utils

Servlet API
CGI
SSI
Servlets
Config Files
Log Files
Classes
Directory Tree

Samples
Sales
Legal
Feedback

 

java.lang.Object
 |
 +--stec.iws.FileCache

public class FileCache

Methods used create and manage file caches.

Methods

Method Description
available Returns the number of free bytes in the specified file cache.
canCache Returns whether the specified file fits into the given file cache.
capacity Returns the maximum size of the specified file cache.
FileCache Constructor used to create a new file cache.
get Used to retrieve the specified file from the given file cache.
remove Used to remove the specified file from the given file cache.
resize Used to grow or shrink the specified file cache to the given size.
size Returns the total number of bytes used in the specified file cache.

available

Returns the number of free bytes in the specified file cache.

Syntax

public synchronized int available()

Parameters

None

Returns

int the number of free bytes left.

Throws

Nothing

Example

int size = fileCache.available()

canCache

Returns whether the specified file fits into the given file cache.

Syntax

public synchronized boolean canCache(IOHandler handler)

Parameters

handler the IO handler to file.

Returns

boolean true if it can fit, or false if it's too large to fit.

Throws

Nothing

Example


IOHandler fh = IOManager.getHandler(filename);
if(!fileCache.canCache(fh))
{
  throw new ServletException("Unable to cache item.");
}

capacity

Returns the maximum size of the specified file cache.

Syntax

public synchronized int capacity()

Parameters

None

Returns

Int the maximum size of the file cache.

Throws

Nothing

Example

int max_size = cache.capacity();

FileCache

Constructor used to create a new file cache.

Syntax

public FileCache(int size)

Parameters

size the maximum size of the file cache in bytes.

Returns

FileCache the new FileCache object.

Throws

Nothing

Example

FileCache cache = new FileCache(1024 * 1024);

get

Used to retrieve the specified file from the given file cache.

Syntax

public synchronized byte[] get(IOHandler handler)
                               throws IOException

Parameters

handler the IO handler to file.

Returns

byte[] an array of bytes containing the file or null if the file could not be retrieved from the file cache.

Throws

IOException if any IO errors occurs.

Notes

Internally get() first searches the file cache for the specified file. If an entry is found in the file cache it then checks to see if the cached image is up to date and if the file still exits. If it is up to date and if the file still exists then it returns a reference to the cached image. If the file no longer exists then it removes the entry and returns null. If the entry is not up to date, the file still exists and there is enough free space available to hold the updated file then it reads the file, it replaces the existing cache image with the new one and returns a reference to the new image. If on the other hand, not enough free space is available to hold the updated entry, then it removes the old entry and returns null. If and entry for the specified file is not found, it then checks to see if the file exits. If it does exist, it then checks to see if enough free space is available to hold the file's image. If enough space exists it then reads the file, creates an entry for it and returns a reference to the new entry. If enough space is not available then it returns null.

Example


IOHandler fh = IOManager.getHandler(filename);
byte[] item = fileCache.get(fh);
if(item == null)
{
  item = read(fh);
}

remove

Used to remove the specified file from the given file cache.

Syntax

public synchronized void remove(IOHandler handler)
                                throws IOException

Parameters

handler the IO handler to file.

Returns

Nothing

Throws

IOException if any IO errors occurs.

Example


IOHandler fh = IOManager.getHandler(filename);
fileCache.remove(fh);

resize

Used to grow or shrink the specified file cache to the given size.

Syntax

public synchronized void resize(int size)

Parameters

size the number of bytes to grow or shrink the file cache.

Returns

Nothing

Throws

Nothing

Example

cache.resize(size);

size

Returns the current size of the specified file cache.

Syntax

public synchronized int size()

Parameters

None

Returns

Int the current size of the file cache.

Throws

Nothing

Example

int size = cache.size();
 top of page
 Built with iScript Copyright © 1997-2000 Servertec. All rights reserved.
Last Modified: Thu Aug 10 13:06:59 EDT 2000