You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jcs-users@jakarta.apache.org by fox1964 <hu...@yahoo.com> on 2009/10/07 05:16:45 UTC

How to Cache A Physical File

I have a large physical file downloaded to my server.   I'd like to cache the
file so that my program can read faster.  I've configured JCS properly.   I
can see the "mycache.key" and "mycache.data" files are updated every time I
use a string for both a key/value pair.    But how can I put a physical file
into cache?   Right now, I use an "FileInputStream" object to read the file,
and put into the cache.

FileInputStream input = new FileInputStream(file);
           cache.put(input);

This seems to go thru without prompting any error message.   But when I
tried to retrieve it, I got a message "java.lang.NullPointerException" when 
           cache.get(key);

I can see the mycache.key file updated, but can NOT see any updates in
mycache.data file by looking at the timestamp.

Any guru can show me what I may do wrong?   Or do you have any sample code
to do this?   Thanks a lot in advance.


-- 
View this message in context: http://www.nabble.com/How-to-Cache-A-Physical-File-tp25779933p25779933.html
Sent from the JCS - Users mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: jcs-users-unsubscribe@jakarta.apache.org
For additional commands, e-mail: jcs-users-help@jakarta.apache.org


RE: How to Cache A Physical File

Posted by Tim Cronin <Ti...@autonomy.com>.
>the files shall be cached to the disk

JCS does this, See indexedDiskCache. If you need the files to be
accessible by external apps then your going to need to write these to
disk on your own
Or if an external process actually places the disk locally.

>Also, that a whole file content shall be cached instead of just a
filename.    

The file input stream is not the file content but the mechanism for
reading 
The content from the disk. As I said creating the input stream is not
that costly. You could read the content then place the content into the
cache. Depending on the size of the content you will end up paying a
memory price. 



-----Original Message-----
From: fox1964 [mailto:huchopin@yahoo.com] 
Sent: Wednesday, October 07, 2009 7:01 PM
To: jcs-users@jakarta.apache.org
Subject: RE: How to Cache A Physical File


Tim,

Thank you so much for your reply.   There are two requirements for this
cache: first, the files shall be cached to the disk; second  Also, that
a
whole file content shall be cached instead of just a filename.   I am
not
using java much, and have not been using that for a long time.   Can you
point me to what object I should rebuild the input stream, which I think
can
be serialized for use in JCS?

do appreciate any input on this.

fox1964



Tim Cronin-2 wrote:
> 
> If you're only using the memory cache you should be able to cache
those
> input streams, but you can't serialize them to disk as they have
native
> file handles tied to them.
> 
> You would need to wrap them and basically rebuild the input stream
> completely.
> 
> It might just be simpler to cache the file name and build the input
> stream.
> 
> If you're concerned about performance I think the reading will be the
> biggest issue and not the creation of the input stream itself.
> 
> 
> -----Original Message-----
> From: fox1964 [mailto:huchopin@yahoo.com] 
> Sent: Tuesday, October 06, 2009 10:17 PM
> To: jcs-users@jakarta.apache.org
> Subject: How to Cache A Physical File
> 
> 
> I have a large physical file downloaded to my server.   I'd like to
> cache the
> file so that my program can read faster.  I've configured JCS
properly.
> I
> can see the "mycache.key" and "mycache.data" files are updated every
> time I
> use a string for both a key/value pair.    But how can I put a
physical
> file
> into cache?   Right now, I use an "FileInputStream" object to read the
> file,
> and put into the cache.
> 
> FileInputStream input = new FileInputStream(file);
>            cache.put(input);
> 
> This seems to go thru without prompting any error message.   But when
I
> tried to retrieve it, I got a message "java.lang.NullPointerException"
> when 
>            cache.get(key);
> 
> I can see the mycache.key file updated, but can NOT see any updates in
> mycache.data file by looking at the timestamp.
> 
> Any guru can show me what I may do wrong?   Or do you have any sample
> code
> to do this?   Thanks a lot in advance.
> 
> 
> -- 
> View this message in context:
>
http://www.nabble.com/How-to-Cache-A-Physical-File-tp25779933p25779933.h
> tml
> Sent from the JCS - Users mailing list archive at Nabble.com.
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: jcs-users-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: jcs-users-help@jakarta.apache.org
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: jcs-users-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: jcs-users-help@jakarta.apache.org
> 
> 
> 

-- 
View this message in context:
http://www.nabble.com/How-to-Cache-A-Physical-File-tp25779933p25796503.h
tml
Sent from the JCS - Users mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: jcs-users-unsubscribe@jakarta.apache.org
For additional commands, e-mail: jcs-users-help@jakarta.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: jcs-users-unsubscribe@jakarta.apache.org
For additional commands, e-mail: jcs-users-help@jakarta.apache.org


Re: How to Cache A Physical File

Posted by Chopin hu <hu...@yahoo.com>.
Jeff,

You are my hero for today.  Can you please send me some code prototype on how to make that work?   Is "ByteBuffer" the actual type you used?   I definitely will try that out soon?  but any piece of your code sample is a great help to me.

Chopin


--- On Fri, 10/9/09, Jeffrey Kesselman <je...@gmail.com> wrote:

> From: Jeffrey Kesselman <je...@gmail.com>
> Subject: Re: How to Cache A Physical File
> To: "JCS Users List" <jc...@jakarta.apache.org>
> Date: Friday, October 9, 2009, 1:14 PM
> I cache file contents in my cache.
> 
> The trick is this... the cache will attempt to serialize
> and cache the java
> object you pass it. So passing it the input stream is
> wrong... it will try
> to cache the input stream object not the contents of the
> stream.
> 
> What I do is read my content into a ByteBuffer and then
> cache that.
> 
> On Fri, Oct 9, 2009 at 12:04 PM, Chopin hu <hu...@yahoo.com>
> wrote:
> 
> > Yes.  Actually, that is exactly what I am looking
> for.  Not clear how to
> > use that yet, though.
> >
> > Thank you so much for all your help on this.
> >
> > Chopin
> >
> >
> > --- On Fri, 10/9/09, Tim Cronin <Ti...@autonomy.com>
> wrote:
> >
> > > From: Tim Cronin <Ti...@autonomy.com>
> > > Subject: RE: How to Cache A Physical File
> > > To: "JCS Users List" <jc...@jakarta.apache.org>
> > > Date: Friday, October 9, 2009, 11:48 AM
> > > You should follow this as it seems
> > > like what you are looking to do.
> > >
> > > https://issues.apache.org/jira/browse/JCS-58
> > >
> > >
> > > -----Original Message-----
> > > From: fox1964 [mailto:huchopin@yahoo.com]
> > >
> > > Sent: Wednesday, October 07, 2009 7:01 PM
> > > To: jcs-users@jakarta.apache.org
> > > Subject: RE: How to Cache A Physical File
> > >
> > >
> > > Tim,
> > >
> > > Thank you so much for your
> reply.   There
> > > are two requirements for this
> > > cache: first, the files shall be cached to the
> disk;
> > > second  Also, that
> > > a
> > > whole file content shall be cached instead of
> just a
> > > filename.   I am
> > > not
> > > using java much, and have not been using that for
> a long
> > > time.   Can you
> > > point me to what object I should rebuild the
> input stream,
> > > which I think
> > > can
> > > be serialized for use in JCS?
> > >
> > > do appreciate any input on this.
> > >
> > > fox1964
> > >
> > >
> > >
> > > Tim Cronin-2 wrote:
> > > >
> > > > If you're only using the memory cache you
> should be
> > > able to cache
> > > those
> > > > input streams, but you can't serialize them
> to disk as
> > > they have
> > > native
> > > > file handles tied to them.
> > > >
> > > > You would need to wrap them and basically
> rebuild the
> > > input stream
> > > > completely.
> > > >
> > > > It might just be simpler to cache the file
> name and
> > > build the input
> > > > stream.
> > > >
> > > > If you're concerned about performance I
> think the
> > > reading will be the
> > > > biggest issue and not the creation of the
> input stream
> > > itself.
> > > >
> > > >
> > > > -----Original Message-----
> > > > From: fox1964 [mailto:huchopin@yahoo.com]
> > >
> > > > Sent: Tuesday, October 06, 2009 10:17 PM
> > > > To: jcs-users@jakarta.apache.org
> > > > Subject: How to Cache A Physical File
> > > >
> > > >
> > > > I have a large physical file downloaded to
> my
> > > server.   I'd like to
> > > > cache the
> > > > file so that my program can read
> faster.  I've
> > > configured JCS
> > > properly.
> > > > I
> > > > can see the "mycache.key" and "mycache.data"
> files are
> > > updated every
> > > > time I
> > > > use a string for both a key/value pair.
> > > But how can I put a
> > > physical
> > > > file
> > > > into cache?   Right now, I
> use an
> > > "FileInputStream" object to read the
> > > > file,
> > > > and put into the cache.
> > > >
> > > > FileInputStream input = new
> FileInputStream(file);
> > > >
> > > cache.put(input);
> > > >
> > > > This seems to go thru without prompting any
> error
> > > message.   But when
> > > I
> > > > tried to retrieve it, I got a message
> > > "java.lang.NullPointerException"
> > > > when
> > > >
> > > cache.get(key);
> > > >
> > > > I can see the mycache.key file updated, but
> can NOT
> > > see any updates in
> > > > mycache.data file by looking at the
> timestamp.
> > > >
> > > > Any guru can show me what I may do
> > > wrong?   Or do you have any
> sample
> > > > code
> > > > to do this?   Thanks a lot in
> advance.
> > > >
> > > >
> > > > --
> > > > View this message in context:
> > > >
> > > http://www.nabble.com/How-to-Cache-A-Physical-File-tp25779933p25779933.h
> > > > tml
> > > > Sent from the JCS - Users mailing list
> archive at
> > > Nabble.com.
> > > >
> > > >
> > > >
> > >
> ---------------------------------------------------------------------
> > > > To unsubscribe, e-mail: jcs-users-unsubscribe@jakarta.apache.org
> > > > For additional commands, e-mail: jcs-users-help@jakarta.apache.org
> > > >
> > > >
> > > >
> > >
> ---------------------------------------------------------------------
> > > > To unsubscribe, e-mail: jcs-users-unsubscribe@jakarta.apache.org
> > > > For additional commands, e-mail: jcs-users-help@jakarta.apache.org
> > > >
> > > >
> > > >
> > >
> > > --
> > > View this message in context:
> > > http://www.nabble.com/How-to-Cache-A-Physical-File-tp25779933p25796503.h
> > > tml
> > > Sent from the JCS - Users mailing list archive
> at
> > > Nabble.com.
> > >
> > >
> > >
> ---------------------------------------------------------------------
> > > To unsubscribe, e-mail: jcs-users-unsubscribe@jakarta.apache.org
> > > For additional commands, e-mail: jcs-users-help@jakarta.apache.org
> > >
> > >
> > >
> ---------------------------------------------------------------------
> > > To unsubscribe, e-mail: jcs-users-unsubscribe@jakarta.apache.org
> > > For additional commands, e-mail: jcs-users-help@jakarta.apache.org
> > >
> > >
> >
> >
> >
> >
> >
> ---------------------------------------------------------------------
> > To unsubscribe, e-mail: jcs-users-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail: jcs-users-help@jakarta.apache.org
> >
> >
> 
> 
> -- 
> ~~ Microsoft help desk says: reply hazy, ask again later.
> ~~
> 


      

---------------------------------------------------------------------
To unsubscribe, e-mail: jcs-users-unsubscribe@jakarta.apache.org
For additional commands, e-mail: jcs-users-help@jakarta.apache.org


Re: How to Cache A Physical File

Posted by Jeffrey Kesselman <je...@gmail.com>.
I cache file contents in my cache.

The trick is this... the cache will attempt to serialize and cache the java
object you pass it. So passing it the input stream is wrong... it will try
to cache the input stream object not the contents of the stream.

What I do is read my content into a ByteBuffer and then cache that.

On Fri, Oct 9, 2009 at 12:04 PM, Chopin hu <hu...@yahoo.com> wrote:

> Yes.  Actually, that is exactly what I am looking for.  Not clear how to
> use that yet, though.
>
> Thank you so much for all your help on this.
>
> Chopin
>
>
> --- On Fri, 10/9/09, Tim Cronin <Ti...@autonomy.com> wrote:
>
> > From: Tim Cronin <Ti...@autonomy.com>
> > Subject: RE: How to Cache A Physical File
> > To: "JCS Users List" <jc...@jakarta.apache.org>
> > Date: Friday, October 9, 2009, 11:48 AM
> > You should follow this as it seems
> > like what you are looking to do.
> >
> > https://issues.apache.org/jira/browse/JCS-58
> >
> >
> > -----Original Message-----
> > From: fox1964 [mailto:huchopin@yahoo.com]
> >
> > Sent: Wednesday, October 07, 2009 7:01 PM
> > To: jcs-users@jakarta.apache.org
> > Subject: RE: How to Cache A Physical File
> >
> >
> > Tim,
> >
> > Thank you so much for your reply.   There
> > are two requirements for this
> > cache: first, the files shall be cached to the disk;
> > second  Also, that
> > a
> > whole file content shall be cached instead of just a
> > filename.   I am
> > not
> > using java much, and have not been using that for a long
> > time.   Can you
> > point me to what object I should rebuild the input stream,
> > which I think
> > can
> > be serialized for use in JCS?
> >
> > do appreciate any input on this.
> >
> > fox1964
> >
> >
> >
> > Tim Cronin-2 wrote:
> > >
> > > If you're only using the memory cache you should be
> > able to cache
> > those
> > > input streams, but you can't serialize them to disk as
> > they have
> > native
> > > file handles tied to them.
> > >
> > > You would need to wrap them and basically rebuild the
> > input stream
> > > completely.
> > >
> > > It might just be simpler to cache the file name and
> > build the input
> > > stream.
> > >
> > > If you're concerned about performance I think the
> > reading will be the
> > > biggest issue and not the creation of the input stream
> > itself.
> > >
> > >
> > > -----Original Message-----
> > > From: fox1964 [mailto:huchopin@yahoo.com]
> >
> > > Sent: Tuesday, October 06, 2009 10:17 PM
> > > To: jcs-users@jakarta.apache.org
> > > Subject: How to Cache A Physical File
> > >
> > >
> > > I have a large physical file downloaded to my
> > server.   I'd like to
> > > cache the
> > > file so that my program can read faster.  I've
> > configured JCS
> > properly.
> > > I
> > > can see the "mycache.key" and "mycache.data" files are
> > updated every
> > > time I
> > > use a string for both a key/value pair.
> > But how can I put a
> > physical
> > > file
> > > into cache?   Right now, I use an
> > "FileInputStream" object to read the
> > > file,
> > > and put into the cache.
> > >
> > > FileInputStream input = new FileInputStream(file);
> > >
> > cache.put(input);
> > >
> > > This seems to go thru without prompting any error
> > message.   But when
> > I
> > > tried to retrieve it, I got a message
> > "java.lang.NullPointerException"
> > > when
> > >
> > cache.get(key);
> > >
> > > I can see the mycache.key file updated, but can NOT
> > see any updates in
> > > mycache.data file by looking at the timestamp.
> > >
> > > Any guru can show me what I may do
> > wrong?   Or do you have any sample
> > > code
> > > to do this?   Thanks a lot in advance.
> > >
> > >
> > > --
> > > View this message in context:
> > >
> > http://www.nabble.com/How-to-Cache-A-Physical-File-tp25779933p25779933.h
> > > tml
> > > Sent from the JCS - Users mailing list archive at
> > Nabble.com.
> > >
> > >
> > >
> > ---------------------------------------------------------------------
> > > To unsubscribe, e-mail: jcs-users-unsubscribe@jakarta.apache.org
> > > For additional commands, e-mail: jcs-users-help@jakarta.apache.org
> > >
> > >
> > >
> > ---------------------------------------------------------------------
> > > To unsubscribe, e-mail: jcs-users-unsubscribe@jakarta.apache.org
> > > For additional commands, e-mail: jcs-users-help@jakarta.apache.org
> > >
> > >
> > >
> >
> > --
> > View this message in context:
> > http://www.nabble.com/How-to-Cache-A-Physical-File-tp25779933p25796503.h
> > tml
> > Sent from the JCS - Users mailing list archive at
> > Nabble.com.
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: jcs-users-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail: jcs-users-help@jakarta.apache.org
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: jcs-users-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail: jcs-users-help@jakarta.apache.org
> >
> >
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: jcs-users-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: jcs-users-help@jakarta.apache.org
>
>


-- 
~~ Microsoft help desk says: reply hazy, ask again later. ~~

RE: How to Cache A Physical File

Posted by Chopin hu <hu...@yahoo.com>.
Yes.  Actually, that is exactly what I am looking for.  Not clear how to use that yet, though.

Thank you so much for all your help on this.

Chopin


--- On Fri, 10/9/09, Tim Cronin <Ti...@autonomy.com> wrote:

> From: Tim Cronin <Ti...@autonomy.com>
> Subject: RE: How to Cache A Physical File
> To: "JCS Users List" <jc...@jakarta.apache.org>
> Date: Friday, October 9, 2009, 11:48 AM
> You should follow this as it seems
> like what you are looking to do.
> 
> https://issues.apache.org/jira/browse/JCS-58
> 
> 
> -----Original Message-----
> From: fox1964 [mailto:huchopin@yahoo.com]
> 
> Sent: Wednesday, October 07, 2009 7:01 PM
> To: jcs-users@jakarta.apache.org
> Subject: RE: How to Cache A Physical File
> 
> 
> Tim,
> 
> Thank you so much for your reply.   There
> are two requirements for this
> cache: first, the files shall be cached to the disk;
> second  Also, that
> a
> whole file content shall be cached instead of just a
> filename.   I am
> not
> using java much, and have not been using that for a long
> time.   Can you
> point me to what object I should rebuild the input stream,
> which I think
> can
> be serialized for use in JCS?
> 
> do appreciate any input on this.
> 
> fox1964
> 
> 
> 
> Tim Cronin-2 wrote:
> > 
> > If you're only using the memory cache you should be
> able to cache
> those
> > input streams, but you can't serialize them to disk as
> they have
> native
> > file handles tied to them.
> > 
> > You would need to wrap them and basically rebuild the
> input stream
> > completely.
> > 
> > It might just be simpler to cache the file name and
> build the input
> > stream.
> > 
> > If you're concerned about performance I think the
> reading will be the
> > biggest issue and not the creation of the input stream
> itself.
> > 
> > 
> > -----Original Message-----
> > From: fox1964 [mailto:huchopin@yahoo.com]
> 
> > Sent: Tuesday, October 06, 2009 10:17 PM
> > To: jcs-users@jakarta.apache.org
> > Subject: How to Cache A Physical File
> > 
> > 
> > I have a large physical file downloaded to my
> server.   I'd like to
> > cache the
> > file so that my program can read faster.  I've
> configured JCS
> properly.
> > I
> > can see the "mycache.key" and "mycache.data" files are
> updated every
> > time I
> > use a string for both a key/value pair.   
> But how can I put a
> physical
> > file
> > into cache?   Right now, I use an
> "FileInputStream" object to read the
> > file,
> > and put into the cache.
> > 
> > FileInputStream input = new FileInputStream(file);
> >           
> cache.put(input);
> > 
> > This seems to go thru without prompting any error
> message.   But when
> I
> > tried to retrieve it, I got a message
> "java.lang.NullPointerException"
> > when 
> >           
> cache.get(key);
> > 
> > I can see the mycache.key file updated, but can NOT
> see any updates in
> > mycache.data file by looking at the timestamp.
> > 
> > Any guru can show me what I may do
> wrong?   Or do you have any sample
> > code
> > to do this?   Thanks a lot in advance.
> > 
> > 
> > -- 
> > View this message in context:
> >
> http://www.nabble.com/How-to-Cache-A-Physical-File-tp25779933p25779933.h
> > tml
> > Sent from the JCS - Users mailing list archive at
> Nabble.com.
> > 
> > 
> >
> ---------------------------------------------------------------------
> > To unsubscribe, e-mail: jcs-users-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail: jcs-users-help@jakarta.apache.org
> > 
> > 
> >
> ---------------------------------------------------------------------
> > To unsubscribe, e-mail: jcs-users-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail: jcs-users-help@jakarta.apache.org
> > 
> > 
> > 
> 
> -- 
> View this message in context:
> http://www.nabble.com/How-to-Cache-A-Physical-File-tp25779933p25796503.h
> tml
> Sent from the JCS - Users mailing list archive at
> Nabble.com.
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: jcs-users-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: jcs-users-help@jakarta.apache.org
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: jcs-users-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: jcs-users-help@jakarta.apache.org
> 
> 


      

---------------------------------------------------------------------
To unsubscribe, e-mail: jcs-users-unsubscribe@jakarta.apache.org
For additional commands, e-mail: jcs-users-help@jakarta.apache.org


RE: How to Cache A Physical File

Posted by Tim Cronin <Ti...@autonomy.com>.
You should follow this as it seems like what you are looking to do.

https://issues.apache.org/jira/browse/JCS-58


-----Original Message-----
From: fox1964 [mailto:huchopin@yahoo.com] 
Sent: Wednesday, October 07, 2009 7:01 PM
To: jcs-users@jakarta.apache.org
Subject: RE: How to Cache A Physical File


Tim,

Thank you so much for your reply.   There are two requirements for this
cache: first, the files shall be cached to the disk; second  Also, that
a
whole file content shall be cached instead of just a filename.   I am
not
using java much, and have not been using that for a long time.   Can you
point me to what object I should rebuild the input stream, which I think
can
be serialized for use in JCS?

do appreciate any input on this.

fox1964



Tim Cronin-2 wrote:
> 
> If you're only using the memory cache you should be able to cache
those
> input streams, but you can't serialize them to disk as they have
native
> file handles tied to them.
> 
> You would need to wrap them and basically rebuild the input stream
> completely.
> 
> It might just be simpler to cache the file name and build the input
> stream.
> 
> If you're concerned about performance I think the reading will be the
> biggest issue and not the creation of the input stream itself.
> 
> 
> -----Original Message-----
> From: fox1964 [mailto:huchopin@yahoo.com] 
> Sent: Tuesday, October 06, 2009 10:17 PM
> To: jcs-users@jakarta.apache.org
> Subject: How to Cache A Physical File
> 
> 
> I have a large physical file downloaded to my server.   I'd like to
> cache the
> file so that my program can read faster.  I've configured JCS
properly.
> I
> can see the "mycache.key" and "mycache.data" files are updated every
> time I
> use a string for both a key/value pair.    But how can I put a
physical
> file
> into cache?   Right now, I use an "FileInputStream" object to read the
> file,
> and put into the cache.
> 
> FileInputStream input = new FileInputStream(file);
>            cache.put(input);
> 
> This seems to go thru without prompting any error message.   But when
I
> tried to retrieve it, I got a message "java.lang.NullPointerException"
> when 
>            cache.get(key);
> 
> I can see the mycache.key file updated, but can NOT see any updates in
> mycache.data file by looking at the timestamp.
> 
> Any guru can show me what I may do wrong?   Or do you have any sample
> code
> to do this?   Thanks a lot in advance.
> 
> 
> -- 
> View this message in context:
>
http://www.nabble.com/How-to-Cache-A-Physical-File-tp25779933p25779933.h
> tml
> Sent from the JCS - Users mailing list archive at Nabble.com.
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: jcs-users-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: jcs-users-help@jakarta.apache.org
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: jcs-users-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: jcs-users-help@jakarta.apache.org
> 
> 
> 

-- 
View this message in context:
http://www.nabble.com/How-to-Cache-A-Physical-File-tp25779933p25796503.h
tml
Sent from the JCS - Users mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: jcs-users-unsubscribe@jakarta.apache.org
For additional commands, e-mail: jcs-users-help@jakarta.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: jcs-users-unsubscribe@jakarta.apache.org
For additional commands, e-mail: jcs-users-help@jakarta.apache.org


RE: How to Cache A Physical File

Posted by fox1964 <hu...@yahoo.com>.
Tim,

Thank you so much for your reply.   There are two requirements for this
cache: first, the files shall be cached to the disk; second  Also, that a
whole file content shall be cached instead of just a filename.   I am not
using java much, and have not been using that for a long time.   Can you
point me to what object I should rebuild the input stream, which I think can
be serialized for use in JCS?

do appreciate any input on this.

fox1964



Tim Cronin-2 wrote:
> 
> If you're only using the memory cache you should be able to cache those
> input streams, but you can't serialize them to disk as they have native
> file handles tied to them.
> 
> You would need to wrap them and basically rebuild the input stream
> completely.
> 
> It might just be simpler to cache the file name and build the input
> stream.
> 
> If you're concerned about performance I think the reading will be the
> biggest issue and not the creation of the input stream itself.
> 
> 
> -----Original Message-----
> From: fox1964 [mailto:huchopin@yahoo.com] 
> Sent: Tuesday, October 06, 2009 10:17 PM
> To: jcs-users@jakarta.apache.org
> Subject: How to Cache A Physical File
> 
> 
> I have a large physical file downloaded to my server.   I'd like to
> cache the
> file so that my program can read faster.  I've configured JCS properly.
> I
> can see the "mycache.key" and "mycache.data" files are updated every
> time I
> use a string for both a key/value pair.    But how can I put a physical
> file
> into cache?   Right now, I use an "FileInputStream" object to read the
> file,
> and put into the cache.
> 
> FileInputStream input = new FileInputStream(file);
>            cache.put(input);
> 
> This seems to go thru without prompting any error message.   But when I
> tried to retrieve it, I got a message "java.lang.NullPointerException"
> when 
>            cache.get(key);
> 
> I can see the mycache.key file updated, but can NOT see any updates in
> mycache.data file by looking at the timestamp.
> 
> Any guru can show me what I may do wrong?   Or do you have any sample
> code
> to do this?   Thanks a lot in advance.
> 
> 
> -- 
> View this message in context:
> http://www.nabble.com/How-to-Cache-A-Physical-File-tp25779933p25779933.h
> tml
> Sent from the JCS - Users mailing list archive at Nabble.com.
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: jcs-users-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: jcs-users-help@jakarta.apache.org
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: jcs-users-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: jcs-users-help@jakarta.apache.org
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/How-to-Cache-A-Physical-File-tp25779933p25796503.html
Sent from the JCS - Users mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: jcs-users-unsubscribe@jakarta.apache.org
For additional commands, e-mail: jcs-users-help@jakarta.apache.org


RE: How to Cache A Physical File

Posted by Tim Cronin <Ti...@autonomy.com>.
If you're only using the memory cache you should be able to cache those
input streams, but you can't serialize them to disk as they have native
file handles tied to them.

You would need to wrap them and basically rebuild the input stream
completely.

It might just be simpler to cache the file name and build the input
stream.

If you're concerned about performance I think the reading will be the
biggest issue and not the creation of the input stream itself.


-----Original Message-----
From: fox1964 [mailto:huchopin@yahoo.com] 
Sent: Tuesday, October 06, 2009 10:17 PM
To: jcs-users@jakarta.apache.org
Subject: How to Cache A Physical File


I have a large physical file downloaded to my server.   I'd like to
cache the
file so that my program can read faster.  I've configured JCS properly.
I
can see the "mycache.key" and "mycache.data" files are updated every
time I
use a string for both a key/value pair.    But how can I put a physical
file
into cache?   Right now, I use an "FileInputStream" object to read the
file,
and put into the cache.

FileInputStream input = new FileInputStream(file);
           cache.put(input);

This seems to go thru without prompting any error message.   But when I
tried to retrieve it, I got a message "java.lang.NullPointerException"
when 
           cache.get(key);

I can see the mycache.key file updated, but can NOT see any updates in
mycache.data file by looking at the timestamp.

Any guru can show me what I may do wrong?   Or do you have any sample
code
to do this?   Thanks a lot in advance.


-- 
View this message in context:
http://www.nabble.com/How-to-Cache-A-Physical-File-tp25779933p25779933.h
tml
Sent from the JCS - Users mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: jcs-users-unsubscribe@jakarta.apache.org
For additional commands, e-mail: jcs-users-help@jakarta.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: jcs-users-unsubscribe@jakarta.apache.org
For additional commands, e-mail: jcs-users-help@jakarta.apache.org