|
What have you tried?
Where are you stuck?
What help do you need?
Sent from my Amstrad PC 1640
Never throw anything away, Griff
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
What help do you need?
I need help in implementing caching the query at the application level.
|
|
|
|
|
It's going to be one of those ...
What help do you need?
Remember that we can't see your screen, access your HDD, or read your mind - we only get exactly what you type to work with. No context, no idea what you have actually tried or what happened when you did, nothing.
Help us to help you ...
Sent from my Amstrad PC 1640
Never throw anything away, Griff
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
I have a form where we can search the information using "User Name", "email" and "zipcode" from the USERS table which has 900,000 records.
For Example User1: searches the information using "test@gmail.com" email address and User2 is also doing the same search after 5 min then I do not want to re-execute the query instead I want to display the results from Cache. My back end is DB2.
I am using OdbcCommand.
USER table has UserID, UserName, Email, Address1, Address 2, Zipcode, State
|
|
|
|
|
It's simple. All you have to do is Google for "mvc cache database results". Start reading and find something that's appropriate for your situation.
Remember though. Server's don't have infinite memory! Be careful what you cache.
|
|
|
|
|
We are not using MVC. We are using ado.net only
|
|
|
|
|
You just compared apples and oranges.
MVC is an ASP.NET web application framework.
ADO.NET is a database querying framework.
In any case, the advice is still the same. Caching is handled at the application level, so if you're using ASP.NET, just change the application type in the Google search.
|
|
|
|
|
1.) What makes you think there's a problem? (Your "example" looks like it will retrieve only one record from a "trivial" database of 900K records). All queries have a "first time" cost due to server data paging that is reduced for subsequent queries hitting the same pages.
2.) What are the the odds that 2 people are running the exact same query at the same time?
3.) How do you insure you are not caching and then returning "stale data"?
(Think hard about the consequences of #3)
"(I) am amazed to see myself here rather than there ... now rather than then".
― Blaise Pascal
|
|
|
|
|
1) What makes you think there's a problem? -- I agree with and my users are ok with this
2)What are the odds that 2 people are running the exact same query at the same time? -- Different users will be using the same query for at least 7- 8 times in a day
3) How do you ensure you are not caching and then returning -- Right now I am using HttpContext.Current.Cache.Get and comparing the parameter value which is not great. It will only work if the same user. But I want to implement at the application level.
Thanks
|
|
|
|
|
#3. No, you missed the point.
When you cache the data from a search query, then the database is updated with new data, how are you going to detect this and invalidate the cached copy of the data so a new search of the same query terms results in an updated dataset?
THIS is what you have to watch out for.
|
|
|
|
|
When you cache the data from a search query, then the database is updated with new data, how are you going to detect this and invalidate the cached copy of the data so a new search of the same query terms results in an updated dataset? God question this is not transactional data and we update data once in a day so i will just cache the query for the half day or 4 hours only.
|
|
|
|
|
Yeah, that's not going to work. Putting an arbitrary value on an items "time to live" will just result in search queries that could be out of date for a smaller period of time.
The code that updates the database has to be able to invalidate cached data. But you have a problem. How is your code going to know which cached queries are affected by a single update to the database?
Caching search queries is a bad idea.
|
|
|
|
|
Dave is absolutely right - by trying to cache data outside of the DB that you are sourcing from, you need to catch everything that happens to your DB and invalid specific portions of your cache if the change might have affected the results of a query. Otherwise, your cached data becomes increasingly out of date and useless.
For example, I issue a stock level request for Product A, and you return "2".
Next time I ask, it's in your cache, so you return "2" without going to the DB.
Then Joe over there sells one, and the DB gets updated to "1"
I ask again, it's in your cache, so you return "2" without going to the DB.
Joe sells anoth, and the DB gets updated to "0"
I ask again, it's in your cache, so you return "2" without going to the DB.
So the customer I'm talking to "knows" there are 2 in stock - and buys one. What happens now?
Unless you "stand in the middle" and pass each query through or serve them from your cache while intelligently invalidating the caches as appropriate, your data gets more and more irrelevant.
And that is going to slow down the whole process as well, because now you have effectively two sources of data processing every single command!
Sent from my Amstrad PC 1640
Never throw anything away, Griff
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
I'm curious - your answer to 1 seems to imply that you and your users don't perceive a problem!
What is the latency on your results return, it seems to me that a query on a 900k should be trivial from a database POV. If it IS the database then look at indexing the user table, if the latency is the network then you have a different problem which should be resolved by your network people not by caching search results.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
hello Code project i have created dictionary with key value pairs form a text file and i want to display the value of a key to a textbox
and edit the value in the textbox and on a button click save to the file this is the code i have so far just not sure how to add to textbox and save it out.
public class BO3_weapon_editor
{
public static string outvalue { get; set; }
public void processfile(string file)
{
Dictionary<string, string> dic = new Dictionary<string, string>();
string data;
{
using (StreamReader reader = new StreamReader(file))
{
string line;
while ((line = reader.ReadToEnd()) != null)
{
var patt = @"(?m)\s*""(.+?)""\s+""(.*?)""\s*";
foreach (Match m in Regex.Matches(line, patt))
{
var k = m.Groups[1].Value;
var v = m.Groups[2].Value;
if (false == dic.ContainsKey(k)) dic[k] = v; else dic[k] += "," + v;
}
outvalue = dic["adsUpAnim"];
}
}
}
}
}
any help would be much appricated.
|
|
|
|
|
It's pretty simple:
textbox1.Text = yourdictionary[key];
yourdictionary[key] = textbox1.Text;
string[] lines = yourdictionary
.Select(kvp=> string.Concat(kvp.Key, "\t", kvp.Value))
.ToArray();
File.WriteAllLines("fullfilename.txt", lines);
Note: i've used tab between key and value. You can replace this separator with another one.
modified 4-Oct-18 2:41am.
|
|
|
|
|
You can read a value from a textBox very simply, by using it's Text property:
string myString = mMyTextBox.Text; And you can use that anywhere you wanted - as the key value for a dictionary for example:
value = myDictionary[myTextBox.Text];
But ... the code you show creates the dictionary, but it then throws it away again, as it is only stored as a local variable in your processfile method. You need to decide what you want to do with your dictionary, and either return it from the method (if it's going to be relatively temporary), store it in a class level variable (if it's going to be needed for the whole life of the class instance), or in a static class level variable (if you need to share it between several instance of the class).
BTW: sort out your indentation! it's a mess, which means the code is probably a mess as well: Visual Studio helps you with the indentation as you go along, so bad indentation normally means your code doesn't compile because the system doesn't understand it!
And never do this:
if (false == dic.ContainsKey(k)) dic[k] = v; else dic[k] += "," + v; There are two things wrong here:
if (false == x) ... That's messy and hard to read. Us etehis instead:
if (!x) ... The other is this:
if (x) y; else z; Indent it, and (certainly while you are a beginner) always use brackets:
if (x)
{
y;
}
else
{
z;
} It doesn't matter what bracketing style you use, as long as you are consistent:
if (x)
{
y;
}
else
{
z;
} Works as well.
So your code ends up as:
if (!dic.ContainsKey(k))
{
dic[k] = v;
}
else
{
dic[k] += "," + v;
} But for advanced users, we'd go with:
dic[k] = dic.ContainsKey(k)) ? dic[k] + "," + v : v;
Sent from my Amstrad PC 1640
Never throw anything away, Griff
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
You probably need to make use of another control than TextBox since there will be more than one pair in the Dictionary. Perhaps take a look at ListBox or DataGridView .
You can loop through the Dictionary like this:
foreach (string s in dic.Keys)
{
}
Once user edits are done, on the button click you can again get all the values and write then to a file. You can opt to use StreamWriter for it.
using (StreamWriter writer = new StreamWriter("file path here"))
{
writer.WriteLine("line to write here");
}
"It is easy to decipher extraterrestrial signals after deciphering Javascript and VB6 themselves.", ISanti[ ^]
|
|
|
|
|
You may wish to consider another data structure if you have the possibility of duplicate keys.
«Where is the Life we have lost in living? Where is the wisdom we have lost in knowledge? Where is the knowledge we have lost in information?» T. S. Elliot
|
|
|
|
|
Hi
I'm trying to implement an OPC client to connect to the FactoryTalk Gateway opc server from Rockwell.
I get an example and I am trying to use it but with some problems.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace RsLinx_OPC_Client
{
public partial class Form1 : Form
{
#region Variables for OPC client
private Opc.URL url;
private Opc.Da.Server server;
private OpcCom.Factory fact = new OpcCom.Factory();
private Opc.Da.Subscription groupRead;
private Opc.Da.Subscription groupWrite;
private Opc.Da.SubscriptionState groupState;
private Opc.Da.SubscriptionState groupStateWrite;
private Opc.Da.Item[] items = new Opc.Da.Item[3];
#endregion
MyOPCObject myOpcObject = new MyOPCObject();
public Form1()
{
InitializeComponent();
}
private void btnConnect_Click(object sender, EventArgs e)
{
url = new Opc.URL("opcda://localhost/FactoryTalk Gateway");
server = new Opc.Da.Server(fact, null);
server.Connect(url, new Opc.ConnectData(new System.Net.NetworkCredential()));
groupState = new Opc.Da.SubscriptionState();
groupState.Name = "Group";
groupState.UpdateRate = 1000;
groupState.Active = true;
groupRead = (Opc.Da.Subscription)server.CreateSubscription(groupState);
groupRead.DataChanged += new Opc.Da.DataChangedEventHandler(group_DataChanged);
items[0] = new Opc.Da.Item();
items[0].ItemName = "[UNTITLED_1]N7:0,L2";
items[1] = new Opc.Da.Item();
items[1].ItemName = "[UNTITLED_1]N11:0,L10";
items[2] = new Opc.Da.Item();
items[2].ItemName = "[UNTITLED_1]B3:0,L2";
items = groupRead.AddItems(items);
groupStateWrite = new Opc.Da.SubscriptionState();
groupStateWrite.Name = "Group Write";
groupStateWrite.Active = false;
groupWrite = (Opc.Da.Subscription)server.CreateSubscription(groupStateWrite);
}
EXception is thrown in the
server.Connect(url, new Opc.ConnectData(new System.Net.NetworkCredential()));
The exception in italian tells that
Quote: Eccezione non gestita di tipo 'System.IO.FileNotFoundException' in OpcNetApi.dll
Ulteriori informazioni: Impossibile caricare il file o l'assembly 'OpcRcw.Dx, Version=1.0.1.21, Culture=neutral, PublicKeyToken=9a40e993cbface53' o una delle relative dipendenze. Impossibile trovare il file specificato.
Which means that it is impossible to load file or assembly 'OpcRcw.Dx, Version=1.0.1.21, Culture=neutral, PublicKeyToken=9a40e993cbface53' or relevant dependecies
Can somebody help?
Regards
|
|
|
|
|
It is not that it is impossible, but that a file cannot be found. The English translation is a fairly common exception:
Quote: Unhandled exception of type 'System.IO.FileNotFoundException' in OpcNetApi.dll
Additional Information: Unable to load file or assembly 'OpcRcw.Dx, Version = 1.0.1.21, Culture = neutral, PublicKeyToken = 9a40e993cbface53' or one of its dependencies. The specified file could not be found.
So, you need to find out why the file OpcRcw.Dx, with the related version, cannot be found in the expected library locations.
|
|
|
|
|
In this folder
Quote: C:\Windows\Microsoft.NET\assembly\GAC_MSIL\OpcNetApi\v4.0_2.1.106.0__78aea80f6827b5ab
I found OpcNetApi.dll
In the
Quote: C:\Windows\Microsoft.NET\assembly\GAC_MSIL\OpcRcw.Dx\v4.0_1.0.2.0__78aea80f6827b5ab
I found OpcRcw.Dx.dll
So at least positive is that files exist. May be missing some registration? I installed everything with the proper installation/licensing process.
|
|
|
|
|
The version information does not match the values in your error message. So somehow either the calling DLL is trying to get the wrong version, or the wrong version was installed. In either case you will need to go back to the suppliers of this software to get the correct versions.
|
|
|
|
|
Is the highlighted part of the folder name containing the dll the version number?
Quote: C:\Windows\Microsoft.NET\assembly\GAC_MSIL\OpcRcw.Dx\v4.0_1.0.2.0__78aea80f6827b5ab
Or better where do I get it?
|
|
|
|
|
The final values in that path certainly look like the version and PublicKeyToken. But since they are different from the values in the error message it looks certain that you have the wrong version of this or the DLL installed. As I said before, you need to go back to the people who produce this software to get the correct version(s).
|
|
|
|