How to perform recaching using memcached? - ruby

I am using memcached to cache a table records. My code is as follows
Rails.cache.fetch('custom_profiles') do
#custom_profiles=CustomProfile.where(:status=>"Active")
end
But whenever a new record has been added , its not getting updated.I want to update this variable whenever the table got edited. If you have any idea about this please share with me.

You can delete an item from cache like this
Rails.cache.delete('custom_profiles')
You might want to do this in some callbacks or Observers

Related

How to delete the ContentType and related db tables in Strapi?

I am using Strapi v3.0.0-beta.18.7
How to delete the ContentType and the related tables from DB ?
I tried the command below, but it is not deleting the db tables.
DELETE http://localhost:1337/content-type-builder/content-types/application::CONTENT_TYPE_NAME.CONTENT_TYPE_NAME
To delete the content-type and related db-tables in Strapi,
You can delete the folder inside /api folder having same name as your content-type
Suppose if you want to delete the "product" content type, you can delete the product folder inside of /api
The database's tables sync is not managed in the Content Type Builder plugin.
By default, Strapi doesn't delete anything from your database structure.
Strapi is customizable but you will not be able to update this.
Here is an issue that talks about this topic - https://github.com/strapi/strapi/issues/1114
The answers above are really helpful but don't explain, how you would actually go about deleting the table manually.
Suppose you run a local default installation with sqlite, you can find your database at .tmp/data.db. To connect to it, you will need a tool that you can get from sqlite directly:
https://sqlite.org/download.html
I guess you can add it to the PATH, but since I am a beginner and I just wanted it to work, i put the sqlite3.exe directly in the folder of the database and ran it.
To open the database, I used .open data.db and tested it with .tables which showed me all the tables that strapi created for me but didn't delete.
To ensure that I found the right table (recipe-cuisine) i looked at the content using .headers on followed by SELECT * FROM "recipe-cuisine";.
I finally deleted the whole table using DROP TABLE "recipe-cuisine";.
There is an awesome documentation on how to do other operations here: https://www.sqlitetutorial.net/
I hope that helps other beginners who struggle to delete the tables. If anybody has suggestions or helpful links with more information, that would be great!
Lets assume you need remove abc collection.
WARNING
Be sure you created backup and there are not other collections that contains abc substring.
Then you need execute commands:
DELETE FROM `users-permissions_permission` WHERE `controller` LIKE '%abc%';
DELETE FROM strapi_permission WHERE `subject` LIKE '%abc%';
DELETE FROM core_store WHERE `key` LIKE '%abc%';
DELETE FROM upload_file_morph WHERE related_type LIKE '%abc%';
DROP TABLE abc;
Then you need execute also:
rm -rf api/abc
Additional notes:
take care about plural names
be sure that there are no relations with other tables in other case you will see error
TypeError: Cannot read property 'globalId' of undefined

DynamoDB delete trigger OldImage

I would like to do some cleanup after a record has been deleted in my DynamoDB table. It would be pretty great if I could use triggers to do this. Unfortunately it seems that OldImage is not passed into "REMOVE" events. The problem is that I need some record attributes other than the keys in order to perform my cleanup and I can't actually read the record anymore to get these attributes once the event has triggered. Is there any other way I can still read attributes of a record that has been deleted in a trigger?
Change the DynamoDB stream to include new and old images.

facade.edit does not change the database

I am working on a JSF project that deals with MySQL DB.
in my backbean method I did:
entityFacade.edit(entity object);
after that I wanted to make sure of the changes, I queried my database to retrieve the edited record, However, the retrieved values are the old ones. it is like entityFacade.edit(entity object); was not made.
I solved this problem by doing this
entityFacade.remove(entity object);
entityFacade.create(entity object);
But the problem is that the object has ID which is auto-increment & I want to keep the old ID.
I don't get why the edit does not change values. what are the possible causes of this problem?
Looking forward to your answers, experts.
For those who are facing the same problem, I solved it as follows:
The problem was not with the facade.edit()
it was with the queries.
Try facade.find(id) to retrieve the records from the database instead of queries. The retrieved records will show the edited data.

Proforma SalesInvoice doesn't show data from all tables

In the salesInvoice ssrs Report i have added a table called carTableEquipTmp which is not there by default, which I insert into along with the other tables(SalesinvoiceTmp and SalesinvoiceHeaderFooterTmp) in SalesInvoiceDP.InsertIntoSalesInvoiceTmp().
Even though my table carTableEquipTmp is getting successfully inserted into, the data doesn't show up on the report if i print a proforma report.
If i add test values to the carTableEquipTmp table in SalesInvoiceDP.processReport() they show up on the proforma invoice, but there's no way for me to get any parameters needed to set in the correct data into the table at this point. If i stop at this point in the debugger none of the data is present because processreport() is being called from a lower level in the code.
I think it might be a problem with maybe pack/unpack or that the proforma code runs from a server instance as the code run when it is proforma is quite different.
I can see that SalesInvoiceJournalPostBase.CreateReportData() creates an instance of salesInvoiceDP
salesInvoiceDP = new SalesInvoiceDP();
salesInvoiceDP.parmDataContract(salesInvoiceContract);
salesInvoiceDP.parmUserConnection(new UserConnection(true));
salesInvoiceDP.createData();
And that this might have something to do with it... but i still cant get the data i want in the carTableEquipTmp table.
So any idea on how to make Ax 2012 accept this new table i have added as it gets inserted into just like the other tables and there seems to be no problem...
I hope you guys can help.
The SalesInvoice report has two data classes you need to look at for the data provider, SalesInvoiceDP and SalesInvoiceDPBase. SalesInvoiceDPBase extends SrsReportDataProviderPreProcess, so there are a couple extra steps you need to take in order to add new datasources to the report.
In the salesInvoiceDP class, there is a method called useExistingReportData(), which re-inserts the pro-forma temp table data under a user connection, so the SrsReportDataProviderPreProcess framework will pick it up in your report. When the pro-forma process creates the report data, it doesn't insert with a user connection so it doesn't get added to the report. This method only gets called when the report is being run pro-forma.
You will need to add your temp table to this method, and follow the pattern for the other tables, so your code will look something like this:
//this is different from the buffer you insert your data with
CarTableEquipTmp localCarTableEquipTmp;
...
recordList = new RecordSortedList(tableNum(carTableEquipTmp));
recordList.sortOrder(fieldNum(carTableEquipTmp, RecId));
//You will need to add a field to relate your temp table
//to the current invoice journal, and insert it in
//InsertIntoSalesInvoiceTmp() if thats where you're inserting your table.
while select localCarTableEquipTmp
where localCarTableEquipTmp.JournalRecId == jourRecId
{
recordList.ins(localCarTableEquipTmp);
}
delete_from localCarTableEquipTmp
where localCarTableEquipTmp.JournalRecId == jourRecId;
recordList.insertDatabase(this.parmUserConnection());
This method re-inserts your data under the framework and deletes the original data. The data that was re-inserted will then get picked up by the framework and show in your report. If you open CarTableEquipTmp in the table browser, you will most likely see data still there from all the times you have tried running the report. This is why we have the delete_from operation after we re-insert the data. When data is inserted under a userConnection, it is automatically deleted when the report is finished
The other method you will want to modify is SalesInvoiceDP.setTableConnections(), and you will just need to add the following line:
CarTableEquipTmp.setConnection(this.parmUserConnection());
This will set the user connection for your table when running regular (not pro-forma). You will probably want to delete the data that is stored currently in your temp table using alt+F9 from the table browser.
Other than that it's all standard RDP stuff, but it sounds like you have that part working fine. Your temp table must be of type "Regular" for this to work.

mutual exclusion in joomla

I created an extension for joomla using:
$id=$database->insertid();
I just covered that if two users are logged on to the site will fit together perform two records in the database and then this statement will return in both cases the same value.
in php you can solve this problem with the transactions.
In joomla how do I solve this problem?
If you have a table you are working with that extends JTable then make sure that you included the check out functionality that is optionally a part of that. THis must means adding a couple of fields like what is in the content table. This will prevent two people from editing the same row at the same time which creates a race condition in which one of the other will lose their data.
Please note that both php and joomla functions to return the last insert id rely on the mysql implementation, and mysql returns the last id inserted on the currently open connection so concurrency is not an issue
#iacoposk8 Your are right it might possible that in very rear case. Such time try to add current logged in user id in your sql query or any where so that it doesn't make any confict. I hope you get it what i want to say. Thanks

Resources