0

I need to store some cache of objects with data. How can I to compress them when put to cache and uncompress when read from it?

I need to cache some pages of store in my client-side logic for my purposes. I think I can have a lot of data, so when records count will be much than 500, I'll clear older values. My cache is just an JavaScript Object, so I need to store all data (which is array of objects) in memory.

As Oleg Volkov said (привет!), I describe my task:

1) there is some ExtJS 4.1 store and combo with multiSelect and pagination

2) I wrote some functional (client and server sides both) which can a) to get page when value I want to set is placed) b) can to setValues values in way they will be stored in foundedValues object to save their values (to set within setRawValue) and can to highlight them when i moving across pages.

3) My pageSize is 25. So, if I want to do setValues([1, 34, 10]), store will get value from firstPage, then load second, get value (34), and will go to first to get 10! But I want to store that all values from 1 to 25 are belongs to first page, and get it from cache, not within Ajax requests.

12
  • Use an (un)compressor algorithm? Or event better, let the browser do the work for you. Commented Jun 8, 2012 at 13:22
  • which algorithms can I to use? Do you know some good implementations in js? Commented Jun 8, 2012 at 13:23
  • Let the browser do it? How does that work? You can GZIP it for transfer from the server, but how would that work for local storage? Commented Jun 8, 2012 at 13:26
  • 3
    The real question is: why do you need to compress your data? If you feel the need of it, you're probably dealing with too much data for an efficient client-side scripting in the first place. Commented Jun 8, 2012 at 13:26
  • 2
    Where are you caching the data? Commented Jun 8, 2012 at 13:28

2 Answers 2

2

You should not do this, quite apart from the considerable effort in space (code) and time (CPU) it would take. Systems where space is at a premium (mobile?) also have only limited CPU power (and it costs ENERGY to compress stuff!), so if you need it you should not do it anyway.

Client-side code (today) should keep the bulk of data - if it is a lot - on the server, and only ask for small chunks on demand. The browser's JS engine may or may not do its own compression, that really is not your business as JS programmer. Same as memory management, which is deliberately kept away from the hands of the JS programmer.

So the answer is: redesign your app to follow the current programming paradigm for JS client/server programming and interaction.

Sign up to request clarification or add additional context in comments.

Comments

1

The effort you put in client side to compress and decompress the data is not worth making the data size smaller in memory.

Still if yo need to do compression check these links.

  1. -
  2. JavaScript implementation of Gzip
  3. Can I compress data in JavaScript?
  4. http://forums.devshed.com/javascript-development-115/compress-strings-arrays-263804.html

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.