I have a class called DataPoint that is defined like the following. Currently, it goes through each property on an object and based on the DataPoint, it does some formatting like padding, trimming, etc... before it will save the record to the database. The current implementation makes a database call for each property which is slow, so my first step is to get everything at once into an in-memory collection. What else can I do below? Is this a good candidate for a singleton since the data rarely changes and/or is it possible to cache it (if so, how)?
public class DataPoint
{
public string Name {get;set;}
public string Justification {get;set;}
public int MaxLength {get;set;}
public string Format {get;set;}
public DataPoint GetDataPoint(string name)
{
var dataPoint =
db.Query<DataPoint>("SELECT * FROM DataPoint WHERE name =
@name", new {name}).FirstOrDefault();
return
dataPoint;
}
public T FormatObj<T>(T obj)
{
foreach (var
propertyInfo in typeof(T).GetProperties())
{
var dataPoint = GetDataPoint(propertyInfo.Name);
//Do formatting on obj Properties such as setting values,
etc...
}
return obj;
}
}
You can use Memory Cache. I use memory cache to cache data rarely changes or at the specific time.
Here is example:
public static T GetCache<T>(string key, Func<T>
initializer) where T : new() {
if (!MemoryCache.Default.Contains(key)) {
try {
T data = initializer();
AddData(key, data);
return (T)MemoryCache.Default[key];
} catch (Exception ex) {
LogHelper.WriteError(MethodBase.GetCurrentMethod(), ex);
return default(T);
}
}
return (T)MemoryCache.Default[key];
}
public static void AddData(string key, object data) {
if (data == null) {
return;
}
var cacheTime =
int.Parse(ConfigurationManager.AppSettings["CachingExpiredTime"]);
AddData(key, data, cacheTime);
}
private static void AddData(string key, object data, int
cacheMinute) {
if (data == null) {
return;
}
var policy = new CacheItemPolicy { AbsoluteExpiration =
DateTime.Now.AddMinutes(cacheMinute) };
MemoryCache.Default.Add(new CacheItem(key, data), policy);
}
I have a class called DataPoint that is defined like the following. Currently, it goes through...
This is a simple C++ class using inheritance, I have trouble getting the program to work. I would also like to add ENUM function to the class TeachingAssistant(Derived class) which is a subclass of Student(Derived Class) which is also a subclass of CourseMember(Base Class). The TeachingAssistant class uses an enum (a user-defined data type) to keep track of the specific role the TA has: enum ta_role {LAB_ASSISTANT, LECTURE_ASSISTANT, BOTH}; You may assume for initialization purposes that the default role is...
Course Class Create a class called Course. It will not have a main method; it is a business class. Put in your documentation comments at the top. Be sure to include your name. Course must have the following instance variables named as shown in the table: Variable name Description crn A unique number given each semester to a section (stands for Course Registration Number) subject A 4-letter abbreviation for the course (e.g., ITEC, PHED, CHEM) number A 4-digit number associated...
C# Hey I am having trouble implementing additonal function to this assignment: Problem: Implement three IComparer classes on Employee - NameComparer, AgeComparer, and PayComparer - that allow Employees to be compared by the Name, Age, and Pay, respectively. Code: Employee.Core.cs using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Employees { partial class Employee { // Field data. private string empName; private int empID; private float currPay; private int empAge; private string empSSN = ""; private string empBene...
Please provide the code for the last part(client side
program).
yes i have all the class implementations.
``` person.h
#ifndef PERSON_H
#define PERSON_H
#include <string>
using namespace std;
class person
{
public:
person();
string getname() const;
string getadd() const;
string getemail() const;
string getphno() const;
string toString() const;
private:
string name;
string add;
string email;
string phno;
};
```person.cpp
#include "person.h"
person::person()
{
name = "XYZ";
add="IIT ";
email="%%%%";
phno="!!!!!";
}
string person::getname() const
{
return name;
}
string person::getadd()...
Hi,
So I have a finished class for the most part aside of the toFile
method that takes a file absolute path +file name and writes to
that file. I'd like to write everything that is in my run method
also the toFile method. (They are the last two methods in the
class). When I write to the file this is what I get.
Instead of the desired
That I get to my counsel. I am
having trouble writing my...
You are to write a class called Point – this will represent a geometric point in a Cartesian plane (but x and y should be ints). Point should have the following: Data: that hold the x-value and the y-value. They should be ints and must be private. Constructors: A default constructor that will set the values to (3, -5) A parameterized constructor that will receive 2 ints (x then y) and set the data to what is...
Hello. I need help writing the following Java Program. Thank you Develop a class encapsulating the concept of a college course, assuming that a course has following attributers: code (for instance COSC1337), a description, and a number of credits (for instance 3). Include a constructor, the accessors, mutators and methods ‘toString’, ‘equals’, and ‘finalize’. Write a client class to test the behavior of the class and its methods. The outline of the class is given as follows: public class Course...
Here is everything I have on my codes, the compiler does not allow me to input my name, it will print out "Please enter your name: " but totally ignores it and does not allow me to input my name and just proceeds to my result of ID and Sale. Please help. I've bolded the part where it I should be able to input my name package salesperson; public class Salesperson { String Names; int ID; double Sales; // craeting...
I am working on this code and keep getting errors like "ERROR: Syntax error: Encountered "<EOF>" at line 1, column 169." and "ERROR: Table/View 'STUDENT' does not exist. ERROR: Table/View 'STUDENT' does not exist. ERROR: Table/View 'STUDENT' does not exist." I do not know why this isn't working. Here is my code: DTCCDatabase.java import java.sql.Connection; import java.sql.DriverManager; import java.sql.SQLException; import java.sql.Statement; /** * This program creates the CoffeeDB database. */ public class DTCCDatabase { public static void main(String[] args)...