You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ignite.apache.org by tusharnakra <tu...@hotmail.com> on 2016/03/30 00:37:03 UTC

How to load cache when reading data from txt files

Hi,

I created a file helloworld.txt. Now I'm reading from the file and then I
want to load the contents of the file into the cache, and whenever the cache
is updated, it should write to the file as well.

This is my code so far:

Please tell me what to do to load the cache and then write from the cache to
the file, as the instructions are not clear from your documentation.

(Also, I have clicked on the subscribe button so many times but I haven't
got any confirmation email in the past 24 hours)

package apache.ignite.schemas;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.nio.file.StandardOpenOption;

public class File {

        public static void main(String[] args) {
               
                FileRead();
                FileWrite();
        }
               
                public static void FileRead()
                {
                try {
                 BufferedReader in = new BufferedReader
                 (new FileReader("/Desktop/helloworld.txt"));
                 String str;
                 while ((str = in.readLine()) != null) {
                    System.out.println(str);
                 }
                 System.out.println(str);
                 }
                 catch (IOException e) {
                 }
              }
               
                public static void FileWrite() {
                        try {
                           
Files.write(Paths.get("/Desktop/helloworld.txt"), "Hello World".getBytes(),
StandardOpenOption.APPEND);
                        }catch (IOException e) {
                            //exception handling left as an exercise for the
reader
                        }
                }
        }



--
View this message in context: http://apache-ignite-users.70518.x6.nabble.com/How-to-load-cache-when-reading-data-from-txt-files-tp3750.html
Sent from the Apache Ignite Users mailing list archive at Nabble.com.

Re: How to load cache when reading data from txt files

Posted by vkulichenko <va...@gmail.com>.
Hi,

If you need write through, you should implement CacheStore interface [1].
But I'm not sure how you're going to work with files in this case. What if
the entry that already exists is updated?

[1] https://apacheignite.readme.io/docs/persistent-store

-Val



--
View this message in context: http://apache-ignite-users.70518.x6.nabble.com/How-to-load-cache-when-reading-data-from-txt-files-tp3750p3797.html
Sent from the Apache Ignite Users mailing list archive at Nabble.com.