-
Notifications
You must be signed in to change notification settings - Fork 0
vishalshar/CachingLibrary
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
Cache Library How to compile: The jar file is project file from Netbeans. After importing it to the IDE, LoginServiceImplementation class contains the main method with some test cases. How to run : main() method is in LoginServiceImplementation. We can run the code from there. It has few test cases. In this class there is a variable testing change it true to run the last test case. Last test case required some different configuration than other test cases. 1) Why not Queue and Map in Cache: Using a ConcurrentLinkedQueue in cache could have reduced the O(n) cost of adding to cache to O(1). Initially I was using queue to keep the userId which was natural ordered with time in which they logged in. With Queue there were some limitation viz. when someone updates the login time of user which is before the current time then in queue I will have to rearrange everything since queue is in sequence of userId. (aligned by time) I might not be clear in what I was trying to say so here is an example: users logged in the system UID Time 1 - 6:00 AM 2 - 7:00 AM 3 - 8:00 AM So the queue for the above 3 entry will be 1-2-3 (which is in natural ordering with respect to time) so this queue will work fine until I use the setLastLoginForUser from FakeDB because it can set any date with any userId and the time can be less than current time which will break the natural ordering in queue. Resulting in rearranging of Queue every time. I hope I was clear in explaining why I didn't use queue with map. 2) Database updates and cache sync : I struggled alot on how to keep the cache updated. Because if the cache is not updated with every update to DB its of no use using cache. Finally I ended up with a solution to update the cache as soon as any query hit the DB and made changes to setLastLoginForUser() method of FakeDB class. 3) Static methods in Cache : Major concern I had since beginning was keeping the cache updated with any update in database. So the solution which I could think of was make an update to cache whenever we are updating the DB. That was the reason I choose keeping methods of cache static so that it can be accessible from FakeDB class. + Reasons for implementing cache : 1) speed and performance : By implementing cache we gain more speed in executing query thereby gaining performance in the application. 2) better user experience : Better performance means faster and better user experience. 3) With cache we will be able to handle more traffic. Q- How does this cache improve performance: A- Cache helps to avoid hitting DB for every query. Its like a small copy of DB in ur program which will help in answering most of the frequent queries. More Effective: It will be very effective if the insert query are less and retrieve queries are more. This will serve the purpose of the cache. Example calling hasUserLoggedInWithin24 1000 times and calling UseJustLoggedIn 0 times.
About
Caching Library for keeping record of users logged in the system in last 24 hours
Topics
Resources
Stars
Watchers
Forks
Releases
No releases published
Packages 0
No packages published