473,388 Members | 1,177 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,388 software developers and data experts.

Array Caching

I would like to cache a list of names of the last 5 users in server cache.
and when a new user visits this page it would delete the oldest user in the
last and add the new user.

pseudo code

string[] actUserList;
actUserList[] = (string[])Cache[("AUL")];
//delete oldest user code
Cache.Insert ("AUL", actUserList[] + getUsername());

String actUserListNew[] = (string[])Cache[("AUL")]; //updated active user
list

Thanks,

Aaron
Nov 18 '05 #1
5 1492
Ok, I understand what you want. What I don't understand is what your problem
is. Do you want an object that will maintain a list of 5 (or a configurable
number) user names?
--
Shiv R. Kumar
http://www.matlus.com
Nov 18 '05 #2
My problem is I don't know how to write this code. :) im new to c#.
is. Do you want an object that will maintain a list of 5 (or a configurable number) user names? Yes, a list of 5

thanks in advance

"Shiv Kumar" <sh***@erolsnoooospaaaam.com> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl... Ok, I understand what you want. What I don't understand is what your problem is. Do you want an object that will maintain a list of 5 (or a configurable number) user names?
--
Shiv R. Kumar
http://www.matlus.com

Nov 18 '05 #3
See is this works for you...
_________________________________________
public class UserList{
private int maxCount;

private Queue userQueue;
private UserList()

{

}
public UserList(int maxCount)

{

this.maxCount = maxCount;

userQueue = new Queue(maxCount);

}

public void Add(string userName)

{

lock(userQueue.SyncRoot)

{

if (userQueue.Count == maxCount)

userQueue.Dequeue();

userQueue.Enqueue(userName);

}

}

public string[] GetUsers()

{

string[] users = new string[userQueue.Count];

lock(userQueue.SyncRoot)

{

int i = 0;

foreach(object item in userQueue)

{

users[i] = item.ToString();

i ++;

}

}

return users;

}

}

_______________________________________
--
Shiv R. Kumar
http://www.matlus.com
"Aaron" <ku*****@yahoo.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
My problem is I don't know how to write this code. :) im new to c#.
is. Do you want an object that will maintain a list of 5 (or a

configurable
number) user names?

Yes, a list of 5

thanks in advance

"Shiv Kumar" <sh***@erolsnoooospaaaam.com> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...
Ok, I understand what you want. What I don't understand is what your

problem
is. Do you want an object that will maintain a list of 5 (or a

configurable
number) user names?
--
Shiv R. Kumar
http://www.matlus.com


Nov 18 '05 #4
Sorry, I didn't intend to send the previous message...

The object needs to be in "global" scope so only one instance is ever
created and so there is only *one* list of users. You should probably use
the object tag in global.asax for this

<object id="ListOfUsers" runat="server" class="YourAppNamespace.UserList"
scope="Application" />

You can then refer to this object (in your Pages) as ListOfUsers.

It's possible that the class UserList will need to be a singleton for this
situation. Please note that I've only tested the UserList class in a
non-threaded environment to make sure it works as expected. I have not
tested it in an ASP.NET environment. I've made the class thread-safe (as far
as I know). I'm new to C# and ASP.NET myself :)

all the best.

--
Shiv R. Kumar
http://www.matlus.com
Nov 18 '05 #5
thank you

"Shiv Kumar" <sh***@erolsnoooospaaaam.com> wrote in message
news:uc**************@TK2MSFTNGP09.phx.gbl...
Sorry, I didn't intend to send the previous message...

The object needs to be in "global" scope so only one instance is ever
created and so there is only *one* list of users. You should probably use
the object tag in global.asax for this

<object id="ListOfUsers" runat="server" class="YourAppNamespace.UserList"
scope="Application" />

You can then refer to this object (in your Pages) as ListOfUsers.

It's possible that the class UserList will need to be a singleton for this
situation. Please note that I've only tested the UserList class in a
non-threaded environment to make sure it works as expected. I have not
tested it in an ASP.NET environment. I've made the class thread-safe (as far as I know). I'm new to C# and ASP.NET myself :)

all the best.

--
Shiv R. Kumar
http://www.matlus.com

Nov 18 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: Sims | last post by:
Hi I have a table with something like ID PARENT 0 | -1 1 | -1 2 | 1 3 | 1
15
by: olle | last post by:
Hi folks. I learning asp.net and compare it with traditional asp and Access-developing. The issue is this one: 1/I have this Ms Acceess adp-project application that works fine on my Ms Sql...
28
by: Terry Andersen | last post by:
I have an array that I initialize to zero, like: Buffer = {0x00}; How do I in my code reset this array to all zeros ones more? Without running a whole for loop? Best Regards Terry
2
by: P Ocor | last post by:
I am trying to cache an array. 1st - can I do this and 2nd -what is the syntax please? I have added the namespace System.Web.Caching. I tried cache.add("myArray") = myArray; from here...
0
by: Troy Simpson | last post by:
Hi, I have a website which is made up of dynamic pages. Each page that's loaded has some code which looks at which template to load amongst other things, which causes the page to take a little...
7
by: André Hänsel | last post by:
Hi! This: function foo() { $a = array('a' => 'b', 'c' => 'd'); return array_keys($a); } while ($a = each(foo()))
5
by: Raj | last post by:
What is the purpose of file system caching while creating a tablespace? Memory on the test server gets used up pretty quickly after a user executes a complex query(database is already activated),...
2
by: George1776 | last post by:
All, I've recently upgraded our production ASP.NET/C# application from framework 1.1 to 2.0. Since then I've been plagued by out-of-memory errors and problems with the cache object (which may...
0
by: jason | last post by:
hi experts, support.microsoft.com/kb/917072 and http://msdn.microsoft.com/msdnmag/issues/06/07/WebAppFollies/ As pointed out in these articles, users might get session variables belong to...
4
by: Hermann | last post by:
My site is a bit slow showing the main page so I thought caching query result in PHP will improve performace. Then I read MySQL documentation and saw that MySQL does have a caching feature. So......
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.