0

guys i want some way to store the data generated by some function of class and later on when next request is made to some other function of same class i should be able to access that stored data, basically i am doing this to save the database query repeatedly for same data.
my project is in codeigniter.

My module works as :
1.Generate list of users from table1 and show it to client on front end..(Here i want to store users name and other data in some way like cache or something).
2.Client on front-end will select among those users and insert those users details to table2 in DB. So basically while entering there data to table2 i dont want again to query Table1 and get there details for inserting ..

I m looking for some caching or store data in some global way..also storing data in hidden fields would be bad idea because size of data would be huge and post may create issue if it exceeds max post size.

If there would be some variable from were i can fetch the old stored data and insert it directly into Table2.

this is what i thought initially but didnt got luck with it: global variable in php codeigniter

Community
  • 1
  • 1
Kaushil Rambhia
  • 195
  • 2
  • 6
  • 19
  • 1
    Session if it's on a per user basis; memcache, redis, uAPC or similar if it's common across all users... I'd imagine CI would provide all those options – Mark Baker Apr 05 '14 at 12:30
  • will it not be a problem if its for 4000 users data in session?? – Kaushil Rambhia Apr 05 '14 at 12:32
  • It could be a problem if it's a large volume of data, and you store it for 4000 user sessions (assuming you have 4000 concurrent users)... but if the same data should be accessible to all users, then you don't use session, you use one of the "common across all users" options that I mentioned for caching – Mark Baker Apr 05 '14 at 12:35

2 Answers2

0

CodeIgniter Active Record has something useful for you. Caching of queries.

4000 users data in session might not be the best thing to do

Usage example from the docs

$this->db->start_cache();
$this->db->select('field1');
$this->db->stop_cache();

$this->db->get('tablename');

//Generates: SELECT `field1` FROM (`tablename`)

$this->db->select('field2');
$this->db->get('tablename');

//Generates: SELECT `field1`, `field2` FROM (`tablename`)

$this->db->flush_cache();

$this->db->select('field2');
$this->db->get('tablename');

//Generates: SELECT `field2` FROM (`tablename`)
Sudhir Mishra
  • 578
  • 2
  • 16
0

use some simple and fast key value storage like Memcached or Redis, they can also work in Memory only, and have a real fast lookup of keys (Redis promises Time Complexity of O(1))

sunny
  • 1,156
  • 8
  • 15